September 2015
Intermediate to advanced
266 pages
5h 38m
English
While CAMShift adds complexity to Meanshift, the implementation of the the preceding program using CAMShift is surprisingly (or not?) similar to the Meanshift example, with the main difference being that, after the call to CamShift, the rectangle is drawn with a particular rotation that follows the rotation of the object being tracked.
Here's the code reimplemented with CAMShift:
import numpy as np import cv2 cap = cv2.VideoCapture(0) # take first frame of the video ret,frame = cap.read() # setup initial location of window r,h,c,w = 300,200,400,300 # simply hardcoded the values track_window = (c,r,w,h) roi = frame[r:r+h, c:c+w] hsv_roi = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) mask = cv2.inRange(hsv_roi, np.array((100., 30.,32.)), np.array((180.,120.,255.))) ...
Read now
Unlock full access