OpenCV 2.3 with VS 2008 - Mouse Events

前端 未结 2 1945
陌清茗
陌清茗 2021-02-15 14:31

Obligatory - I\'m a newbie. Have a job that involves programming and I\'m teaching myself as I go. Needless to say as a teacher I get things wrong frequently and thoroughly.

2条回答
  •  庸人自扰
    2021-02-15 14:50

    You can also use the onMouse method as a static method.

    class Graph
    {
    public:
         static void onMouse(int event, int x, int y, void* param)
         {
              //Your code here
         }
    
         //Everything else you may need
    }
    

    Now you should be able to call the onMouse method with:

    cv::setMouseCallback(windowName, onMouse, (void*) param);
    

    The param can be NULL or whatever you want to pass as parameter to the method, but you'll need to make a type-cast to the desired type.

    Hope this was useful. Bye.

提交回复
热议问题