How it works...

The OpenCV tracking API provides access to many different tracking algorithms, such as Median Flow, Kernelized correlation filters (KCF), Tracking-Learning-Detection (TLD), and some others. A tracker can be instantiated via the cv2.TrackerKCF_create method (instead of KCF, you can specify any other supported tracking algorithm name). The tracking model must be initialized for the first frame, with the initial object position specified via the method tracker.init. After that, each frame must be processed with the method tracker.update, which returns the tracking status and current position of the tracked object.

The following output is expected after a few steps (the frame rate figures are, obviously, hardware dependent): ...

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.