I am writing eye tracking code using OS X / X Code / OpenCV 2.2. As part of the Eye Tracker training process, I use cvSetMouseCallback to collect data according to the following: Right-click for the right eye; Left click for the left eye.
However, I found that the program can only work with a left click (CV_EVENT_LBUTTONDOWN), while it does not work with a right click (CV_EVENT_RBUTTONDOWN). At first I thought that these were problems with the trackpad and mouse, but it turned out that I had already set Secondary Click as βRightβ in the car. Appreciate if anyone can shed light on this? Thanks for your time to look at this.
For those interested, I have a simple code snippet for cvSetMouseCallback:
#include <cv.h> #include <cxcore.h> #include <highgui.h> void my_mouse_callback( int event, int x, int y, int flags, void* param ); int main (int argc, const char * argv[]) { CvCapture *capture; IplImage *img; int key = 0; // initialize camera capture = cvCaptureFromCAM( 0 ); // always check assert( capture ); // create a window cvNamedWindow( "video", 1 ); while( key != 'q' ) { // get a frame img = cvQueryFrame( capture ); // set the mouse callback function. cvSetMouseCallback( "video", my_mouse_callback, (void*) img); // always check if( !img ) break; // 'fix' frame cvFlip( img, img, 1 ); img->origin = 0; cvShowImage("video", img ); // quit if user press 'q' key = cvWaitKey( 5 ); } // free memory cvReleaseCapture( &capture ); cvDestroyWindow( "video" ); return 0; } void my_mouse_callback( int event, int x, int y, int flags, void* param ){ //IplImage* image = (IplImage*) param; switch( event ){ case CV_EVENT_LBUTTONDOWN: printf("LBUTTONDOWN\n"); break; case CV_EVENT_RBUTTONDOWN: printf("RBUTTONDOWN\n"); break; case CV_EVENT_FLAG_CTRLKEY: printf("FLAG_LBUTTONDBLCLK\n"); break; } }
opencv mouseevent
CCS
source share