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

Keyboard inputs

Now that we know how to capture a live video stream from the webcam, let's see how to use the keyboard to interact with the window displaying the video stream.

import argparse import cv2 def argument_parser(): parser = argparse.ArgumentParser(description="Change color space of the \ input video stream using keyboard controls. The control keys are: \ Grayscale - 'g', YUV - 'y', HSV - 'h'") return parser if __name__=='__main__': args = argument_parser().parse_args() cap = cv2.VideoCapture(0) # Check if the webcam is opened correctly if not cap.isOpened(): raise IOError("Cannot open webcam") cur_char = -1 prev_char = -1 while True: # Read the current frame from webcam ret, frame = cap.read() # Resize the captured image frame = cv2.resize(frame, ...
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