How to use OpenCV to realize Mouse response to events in C++
C++ how to use OpenCV to achieve mouse response to events, for this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Code implementation
Let's create a new project named opencv--Grabcut, follow the configuration properties (VS2017 configure OpenCV generic properties), and then write # include and main methods in the source file.
In the picture above, we have directly written the callback events of the mouse. This is not the point, but our mouse events.
Let's start with the focus of the mouse event:
Define basic parameters and methods
The title of the display we defined in the above figure is src, which will not be discussed, and then two Mat, a rectangular rect, are defined. There is also a showimage () method at the bottom, which is how to display the image.
The most important method is onMouse (int event, int x drawing int y, int flags, void* param), which is used to handle mouse operations.
Operation logic of mouse
The mouse writes three events when the left button is pressed, when the left button is pressed and when the mouse is moved, and when the left button is released.
Image display method
This is the answer to the question about how to use OpenCV to respond to events in C++. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.