I am trying to visualize the output of calcOpticalFlowPyrLK()
(OpenCv v3.0.0). I am not trying to draw whole image with optical flow, only the direction arrow. The problem is, I can't get to the output as in the examples. Every 10 frames I renew the points for the calculation of the flow. The function itself
calcOpticalFlowPyrLK(CentroidFrOld, CentroidFrNow, mc, CornersCentroidNow, feat_found, feat_errors, Size(15, 15), 2, cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 10, 0.03), 0);
Where CentroidFrOld
is grayscale frame, CentroidFrNow
is grayscale frame+1, mc
is a vector<Point2f>
array of points and CornersCentroidNow
is an empty array waiting to be filled with new points.
When drawing them I use simple code:
for (size_t i = 0; i < CornersCentroidNow.size(); i++){
if (feat_errors[i] > MAX_ERR || feat_found[i] == 0) continue;
Point p0(ceil(mc[i].x), ceil(mc[i].y)); // are the points of interest (centroids of contours)
Point p1(ceil(CornersCentroidNow[i].x), ceil(CornersCentroidNow[i].y));
arrowedLine(empty, p0, p1, Scalar(0, 0, 255), 2, 8, 0, 0.2);
}
after this block of code. When I draw them every frame I get this output:
If I update the previous frame used for calcOpticalFlowPyrLK()
function
CentroidFrOld = CentroidFrNow.clone();
I get this output (the line is short and it is moving foward every 10 frames - as set to get new points)
If the previous points happen to be next points as well
CentroidFrOld = CentroidFrNow.clone();
mc = CornersCentroidNow;
I get this output (the line is short, but it is moving along with the object)
The desired output I can't achieve is
Do I need to manually lengthen the line? Noone is doing so in similar examples of implemantation of Optical Flow