Subscribe:

Ads 468x60px

Saturday, April 14, 2012

OpenCV and Mouse

Hi all 

      A simple program to show the  interaction with mouse using OpenCV




//code---------------------------------------------


#include "cv.h"
#include "highgui.h"

#include <iostream>

#include <stdio.h>
#include <stdlib.h>





IplImage* capture;

CvPoint pt1;
CvFont font;
void on_mouse(int event,int x ,int y,int flags,void* param)
{


std::cout<<"X="<<"\t"<<x<<"\t"<<"Y="<<"\t"<<y<<std::endl;
}


int main(int argc,
char** argv
)

{

 
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 1.0, 1.0, 0, 1, CV_AA);

    capture = cvLoadImage(argv[1], 1);
    cvNamedWindow( "result", 1 );
    cvShowImage( "result",capture );
    //Mouse call back funtion

    cvSetMouseCallback("result",on_mouse,0);

    cvWaitKey(0);
    cvReleaseImage( &capture );
    cvDestroyWindow("result");


}


Output


0 comments:

Post a Comment