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:傳給回調函數的參數
- event是 CV_EVENT_*變量之一
- x和y是鼠標指針在圖像座標系的座標(不是窗口座標系)
- flags是CV_EVENT_FLAG的組合, param是用戶定義的傳遞到setMouseCallback函數調用的參數。
#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