【OpenCV_11】利用OpenCV检测鼠标点击及移动 Detect Mouse Clicks and Moves

OpenCV支持检测鼠标事件。鼠标事件包括鼠标点击及鼠标移动在一个特定的OpenCV创建的窗口。

OpenCV 实例


这个其是非常简单。只要利用OpenCV的C++代码定义一个回调函数连接到OpenCV定义的窗口。只要鼠标有事件发生,回调函数就会被调用。回调函数也会给出鼠标事件的坐标。(e.g - (x, y)鼠标的坐标).


#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;

void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
     if  ( event == EVENT_LBUTTONDOWN )
     {
          cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
     }
     else if  ( event == EVENT_RBUTTONDOWN )
     {
          cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
     }
     else if  ( event == EVENT_MBUTTONDOWN )
     {
          cout << "Middle button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
     }
     else if ( event == EVENT_MOUSEMOVE )
     {
          cout << "Mouse move over the window - position (" << x << ", " << y << ")" << endl;

     }
}

int main(int argc, char** argv)
{
     // Read image from file 
     Mat img = imread("/Users/iDreamboat/Desktop/OpenCV/RG.JPG"&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值