March 2019
Intermediate to advanced
532 pages
13h 2m
English
Th next example gives you an introduction into how to handle mouse events with OpenCV. The cv2.setMouseCallback() function performs this functionality. The signature for this method is as follows:
cv2.setMouseCallback(windowName, onMouse, param=None)
This function establishes the mouse handler for the window named windowName. The onMouse function is the callback function, which is called when a mouse event is performed (for example, double-click, left-button down, left-button up, among others). The optional param parameter is used to pass additional information to the callback function.
So the first step is to create the callback function:
# This is the mouse callback function:def draw_circle(event, x, y, flags,