Tracking objects using different algorithms via the tracking API
In this recipe, you will learn how to use the different tracking algorithms implemented in the OpenCV tracking contrib module. Different tracking algorithms have different properties in terms of accuracy, reliability, and speed. Using the tracking API, you can try to find the one that best suits your needs.
Getting ready
Before you proceed with this recipe, you need to install the OpenCV 3.x Python API package and the matplotlib package. OpenCV must be built with contrib modules, because the tracking API isn't a part of the main OpenCV repo.
How to do it...
To complete this recipe, perform the following steps:
- Import the module:
import cv2
- Create the main window and loop over the different trackers:
cv2.namedWindow('frame') for name, tracker in (('KCF', cv2.TrackerKCF_create), ('MIL', cv2.TrackerMIL_create), ('TLD', cv2.TrackerTLD_create)): tracker = tracker() initialized = False...