Skip to Content
OpenCV with Python By Example
book

OpenCV with Python By Example

by Prateek Joshi
September 2015
Beginner to intermediate
296 pages
5h 57m
English
Packt Publishing
Content preview from OpenCV with Python By Example

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

OpenCV 4 with Python Blueprints - Second Edition

OpenCV 4 with Python Blueprints - Second Edition

Dr. Menua Gevorgyan, Michael Beyeler (USD), Arsen Mamikonyan, Michael Beyeler
OpenCV By Example

OpenCV By Example

Prateek Joshi, David Millán Escrivá, Vinícius G. Mendonça
OpenCV 3 Computer Vision with Python Cookbook

OpenCV 3 Computer Vision with Python Cookbook

Aleksei Spizhevoi, Aleksandr Rybnikov

Publisher Resources

ISBN: 9781785283932Supplemental Content