简体   繁体   English

使用C ++在OpenCV中单击鼠标功能

[英]Mouse Click function in OpenCV using C++

I am relatively new to OpenCV and I am trying to work on virtual mouse. 我是OpenCV的新手,我正在努力研究虚拟鼠标。 I figured out how to detect different colors and filter them out. 我想出了如何检测不同的颜色并过滤掉它们。 I couldn't find how to make mouse click when specific color is detected. 当检测到特定颜色时,我找不到如何使鼠标单击。 Here my sample code: 这是我的示例代码:

if (b == 1){
        if (x >= 0 && y >= 0 && PosX >= 0 && PosY >= 0)

        //Here is the function to left clicking the mouse

    }

I figured out how to move the mouse. 我想出了如何移动鼠标。 I used SetCursorPos(x,y) . 我使用了SetCursorPos(x,y) I would appreciate any help. 我将不胜感激任何帮助。 Thank you in advance! 先感谢您!

The mouse click event comes with the x,y of the mouse position. 鼠标单击事件带有鼠标位置的x,y。 Use these coordinates for accessing the image. 使用这些坐标访问图像。
Take a look at SetMouseCallback() . 看看SetMouseCallback()
Here's an example of how to use it. 这是一个如何使用它的例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM