Note that there are some explanatory texts on larger screens.

plurals
  1. POMouse event handling with cvSetMouseCallback
    primarykey
    data
    text
    <p>I am writing a code for eye tracker using OS X / X Code / OpenCV 2.2. As part of the Eye Tracker training process, I am using cvSetMouseCallback to capture the data as per following: Right click for right eye; Left click for left eye.</p> <p>However, I found that the program could only work with left click (CV_EVENT_LBUTTONDOWN) while it does not work with right click (CV_EVENT_RBUTTONDOWN). At first, I thought it was a trackpad and mouse setting issues, however, it turns out that I have already set both Secondary Click as "Right" in the machine. Appreciate if someone could shed some light on this? Thank you for your time to look into this.</p> <p>For those interested, I have a simple code snippet for cvSetMouseCallback:</p> <pre><code>#include &lt;cv.h&gt; #include &lt;cxcore.h&gt; #include &lt;highgui.h&gt; 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-&gt;origin = 0; cvShowImage("video", img ); // quit if user press 'q' key = cvWaitKey( 5 ); } // free memory cvReleaseCapture( &amp;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; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload