2

I am relatively new to OpenCV and I am trying to work on virtual mouse. 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). I would appreciate any help. Thank you in advance!

1 Answer 1

5

The mouse click event comes with the x,y of the mouse position. Use these coordinates for accessing the image.
Take a look at SetMouseCallback().
Here's an example of how to use it.

Sign up to request clarification or add additional context in comments.

2 Comments

But is there a special function to do that. For example to move the mouse there is SetCursorPos(x,y) but what is the function for the click event?
Thank you @Adi, now I get the whole idea of handling mouse click event.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.