OpenCV Return value from mouse callback function

前端 未结 3 804
忘了有多久
忘了有多久 2021-01-14 06:39

In OpenCV I want to return the point position like Point(x,y) to the main() function that I click on the image in the mouse callback function . Is there anyway other than se

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-14 06:48

    to expand Safirs idea there, apart from a class or such, you could just pass in the point itself:

    void on_mouse( int e, int x, int y, int d, void *ptr )
    {
        Point*p = (Point*)ptr;
        p->x = x;
        p->y = y;
    }
    
    Point p;
    namedWindow("win");
    setMouseCallback("win",on_mouse, (void*)(&p) );
    
    // changed value of p will be accessible here 
    

提交回复
热议问题