Mouse inputs

In this section, we will see how to use the mouse to interact with the display window. Let's start with something simple. We will write a program that will detect the quadrant in which the mouse click was detected. Once we detect it, we will highlight that quadrant.

import cv2 import numpy as np def detect_quadrant(event, x, y, flags, param): if event == cv2.EVENT_LBUTTONDOWN: if x > width/2: if y > height/2: point_top_left = (int(width/2), int(height/2)) point_bottom_right = (width-1, height-1) else: point_top_left = (int(width/2), 0) point_bottom_right = (width-1, int(height/2)) else: if y > height/2: point_top_left = (0, int(height/2)) point_bottom_right = (int(width/2), height-1) else: point_top_left = (0, 0) point_bottom_right ...

Get OpenCV: Computer Vision Projects with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.