Training an object detector is bit of a complicated task. You need to have a proper training dataset with the relevant bounding boxes, and then use something like a HOG feature extractor with a SVM classifier for the detection - such as the Dlib Object Detection classes (link).
But that's a lot of work if you just need to track an object across a limited number of frames, or just need to detect motion or direction of movement. For that, we can easily use the Correlation Trackers feature in Dlib.
Object Tracking |
See it in action,
Object Tracking in Action |
Correlation Trackers - as their name suggests - works by correlating a set of pixels from one frame to the next.
Let's see how to build it.