how to use cv::setMouseCallback

后端 未结 2 859
情歌与酒
情歌与酒 2021-01-19 16:36

I\'m trying to use cv::setMouseCallback in my c++ project. I just don\'t get it. let that I habe a class Stuff how can tell this class you got a frame and run the cv::se

2条回答
  •  执念已碎
    2021-01-19 17:26

    you must declare a mouse handler as static inside your class. For instance, I have a dragger with a member mouser, that I want to be called. I declare an helper static void mouser, that cast the void* received and calls the member:

    class dragger {
    
    void mouser(int event, int x, int y) {
      current_img = original_img.clone();
      Point P(x, y);
      ...
    }
    static void mouser(int event, int x, int y, int, void* this_) {
      static_cast(this_)->mouser(event, x, y);
    }
    

    and instance in dragger constructor in this way

    dragger(string w, Mat m) :
        window_id(w), status(0), original_img(m), /*black(0, 0, 0),*/ K(5, 5)
    {
       ...
       setMouseCallback(w, mouser, this);
    }
    
    ...
    }
    

提交回复
热议问题