Interacting with a live video stream

Let's see how we can use the mouse to interact with live video stream from the webcam. We can use the mouse to select a region and then apply the "negative film" effect on that region, as shown next:

Interacting with a live video stream

In the following program, we will capture the video stream from the webcam, select a region of interest with the mouse, and then apply the effect:

import cv2 import numpy as np def draw_rectangle(event, x, y, flags, params): global x_init, y_init, drawing, top_left_pt, bottom_right_pt if event == cv2.EVENT_LBUTTONDOWN: drawing = True x_init, y_init = x, y elif event == cv2.EVENT_MOUSEMOVE: if drawing: top_left_pt = ...

Get OpenCV with Python By Example 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.