我将此用作跟踪算法的基础功能。
//1. detect the 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
函数的输入是前一帧图像上的一组点,输出则是它们在下一帧图像上的对应点。如果我有前一帧图像上的一个随机像素 (x, y),那么如何使用 OpenCV 光流函数计算出这个像素在下一帧图像上的位置呢?
goodFeaturesToTrack
检测特征,然后光流方法会简单地跟踪它们。如果您想在每个帧中保持一定数量的特征,则需要检测成功跟踪到当前帧的特征数量,然后尝试检测其他要跟踪到下一帧的特征。另一种选择是在每个帧中检测特征,然后使用此页面上的函数计算描述符并匹配这些描述符。 - Chris