February 2020
Intermediate to advanced
372 pages
9h 26m
English
Although CamShift is a more complex algorithm than MeanShift, OpenCV provides a very similar interface for the two algorithms. The main difference is that a call to cv2.CamShift returns a rectangle with a particular rotation that follows the rotation of the object being tracked. With just a few modifications to the preceding MeanShift example, we can instead use CamShift and draw a rotated tracking rectangle. All of the necessary changes are highlighted in bold in the following excerpt:
import cv2import numpy as np# ... Initialize the tracking window and histogram as previously ...success, frame = cap.read()while success: # Perform back-projection of the HSV histogram onto the frame. hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) ...