How it works...

To create the Median Flow tracker, we need to use cv2.TrackerMedianFlow_create. This function returns an instance of our tracker. Next, the tracker should be initialized with the object to follow. This can be done with the init function call. This function should be invoked for the tracker instance with the following arguments: the frame with the object to track and the bounding box of the object in an (x, y, width, height) format. The function returns True if initialization has been completed successfully.

When we have a new frame, we want to get a new bounding box for the object. To do this, we need to call the tracker instance's update function, with the new frame as an argument. The values returned from this routine are ...

Get OpenCV 3 Computer Vision with Python Cookbook 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.