Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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;