I use the following functions as a base of my tracking algorithm.
//1. detect the features what i mean, this function extract the only good features,
cv::goodFeaturesToTrack(gray_prev, // the image
features, // the output detected features
max_count, // the maximum number of features
qlevel, // quality level
minDist); // min distance between two features
// 2. track features
cv::calcOpticalFlowPyrLK(
gray_prev, gray, // 2 consecutive images
points_prev, // input point positions in first im
points_cur, // output point positions in the 2nd
status, // tracking success
err); // tracking error
cv::calcOpticalFlowPyrLK
takes vector of points from the previous image as input, and returns appropriate points on the next image.
Suppose I want to calculate the opical flow for each pixle instead of good features
in the other meaning, start to calculate the optical flow from(1,1 ) to (m,n)
cv::calcOpticalFlowPyrLK does sparse OF, ie from feature points, if you want it for each pixel, use
calcOpticalFlowFarneback .
Computes a dense optical flow (using the Gunnar Farneback’s algorithm).