Thursday, 20 June 2013

Hello Friends!!

In this post I will show you how you can implement mouse interactivity in OpenCV programs. First step is to declare and define our mouse handler. The prototype of handler function is as follows:

void mouseHandler( int event, int x, int y, int flags, void *param );

Here (x,y) is coordinate of the point at which mouse event occurred. Now we define the body of handler:

void mouseHandler( int event, int x, int y, int flags, void *param )
{
    /* user clicked*/
    if( event == CV_EVENT_LBUTTONUP )

    {
            // do whatever you are pleased with
    }
}


Now set mouse handler using cvSetMouseCallback function:

cvSetMouseCallback( "window_name_here", mouseHandler, NULL );

Enjoy!!

0 comments:

Post a Comment