我目前正在开展一个对象跟踪项目,并使用过c ++,opencv.我成功地使用了Farneback密集光流来实现分割方法,例如k均值(使用每帧中的位移).现在我想用Lucas Kanade稀疏方法做同样的事情.但是这个函数的输出是:
nextPts - 2D点的输出向量(具有单精度浮点坐标),包含第二个图像中输入要素的计算新位置; 当传递OPTFLOW_USE_INITIAL_FLOW标志时,向量必须与输入中的大小相同.
(如官方网站所述)
我的问题是我将如何将结果以Mat流程为例.我到目前为止尝试过:
//实现Lucas Kanade算法
cvCalcOpticalFlowPyrLK(frame1_1C, frame2_1C, pyramid1, pyramid2,
frame1_features, frame2_features, number_of_features,
optical_flow_window, 5, optical_flow_found_feature,
optical_flow_feature_error, optical_flow_termination_criteria,
0);
// Calculate each feature point's coordinates in every frame
CvPoint p,q;
p.x = (int) frame1_features[i].x;
p.y = (int) frame1_features[i].y;
q.x = (int) frame2_features[i].x;
q.y = (int) frame2_features[i].y;
// Creating the arrows for imshow
angle = atan2((double) p.y - q.y, (double) p.x - q.x);
hypotenuse = sqrt(square(p.y - q.y) + square(p.x - q.x));
/* Here …Run Code Online (Sandbox Code Playgroud)