# Optical Flow vizualization

I am trying to visualize the output of calcOpticalFlowPyrLK(). 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. 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 I swap the prew points and 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)

What I aim to get is a long straight arrow aiming in the right direction, but I am not able to achieve something similar as in the flow tutorial. The only thing that author doesn't do is to find new points every few frames. Something like this

edit retag close merge delete