opencv中setMousecallback的用法

来源:互联网 发布:大连淘宝模特 编辑:程序博客网 时间:2024/05/17 06:18

    opencv中的鼠标响应的函数是setMouseCallback(),可以实现画图的功能。

    c++: void setMousecallback(const string& winname, MouseCallback onMouse, void* userdata=0)

  •     winname:窗口的名字
  •     onMouse:鼠标响应函数,回调函数。指定窗口里每次鼠标时间发生的时候,被调用的函数指针。 这个函数的原型应该为void on_Mouse(int event, int x, int y, int flags, void* param);
  •     userdate:传给回调函数的参数 
    
     void on_Mouse(int event, int x, int y, int flags, void* param);
  • event是 CV_EVENT_*变量之一
  • x和y是鼠标指针在图像坐标系的坐标(不是窗口坐标系) 
  • flags是CV_EVENT_FLAG的组合, param是用户定义的传递到setMouseCallback函数调用的参数。

附event:

#defineCV_EVENT_MOUSEMOVE      0

#defineCV_EVENT_LBUTTONDOWN    1

#defineCV_EVENT_RBUTTONDOWN    2

#defineCV_EVENT_MBUTTONDOWN    3

#defineCV_EVENT_LBUTTONUP      4

#defineCV_EVENT_RBUTTONUP      5

#defineCV_EVENT_MBUTTONUP      6

#defineCV_EVENT_LBUTTONDBLCLK  7

#defineCV_EVENT_RBUTTONDBLCLK  8

#defineCV_EVENT_MBUTTONDBLCLK  9

 

#defineCV_EVENT_FLAG_LBUTTON   1

#defineCV_EVENT_FLAG_RBUTTON   2

#defineCV_EVENT_FLAG_MBUTTON   4

#defineCV_EVENT_FLAG_CTRLKEY   8

#defineCV_EVENT_FLAG_SHIFTKEY  16

#defineCV_EVENT_FLAG_ALTKEY    32