How to do it...

We will now start with the tracing of feature points in a video, frame by frame. Let's take a look at the following steps:

  1. To start the tracking process, the first thing to do is to detect the feature points in an initial frame. You then try to track these points in the next frame.
  2. Obviously, since we are dealing with a video sequence, there is a good chance that the object, on which the feature points are found, has moved (this motion can also be due to camera movement). Therefore, you must search around a point's previous location in order to find its new location in the next frame. This is what the cv::calcOpticalFlowPyrLK function accomplishes. That is, you input two consecutive frames and a vector of feature points in ...

Get OpenCV 4 Computer Vision Application Programming Cookbook - Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.