O'Reilly logo

OpenCV with Python By Example by Prateek Joshi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required