Ask Your Question
0

passing and returning values from mouse handler function

asked 2013-04-13 04:20:27 -0600

am gravatar image

i have implemented the mouse handler function to get pixel location. i want to use this location in main function is there a way to use these values in main function.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-04-13 04:37:37 -0600

berak gravatar image

you can use the userdata ptr in the event handler to do that, here's an example, that passes in a Point, holding the Mouse position

void onmouse( int event, int x, int y, int d, void *ptr )
{
     if ( event == 1 ) // lbutton down
     {
         cv::Point* p = (cv::Point*)ptr;
         p->x = x;
         p->y = y;
     }
}

int main()
{
    cv::namedWindow("video", 1);
    cv::Point point;
    cv::setMouseCallback( "video", onmouse, (void*)(&point) );
    // whenever the mouse is clicked, point holds the current value here
    return 0;
}
edit flag offensive delete link more

Comments

thank you it worked

am gravatar imageam ( 2013-04-13 04:56:06 -0600 )edit

Question Tools

Stats

Asked: 2013-04-13 04:20:27 -0600

Seen: 2,489 times

Last updated: Apr 13 '13