I'm running the sparse optical flow demo at link here and I'm simply trying to draw a line between a single point being tracked across all the frames in a video.
Within the for loop,
int LastX = 0;
int LastY = 0;
int px, py;
else if( !points[0].empty() )
{
vector<uchar> status;
vector<float> err;
if(prevGray.empty())
gray.copyTo(prevGray);
calcOpticalFlowPyrLK(prevGray, gray, points[0], points[1], status, err, winSize,
3, termcrit, 0, 0.001);
size_t i, k;
for( i = k = 0; i < points[1].size(); i++ )
{
if( addRemovePt )
{
if( norm(point - points[1][i]) <= 5 )
{
addRemovePt = false;
continue;
}
}
if( !status[i] )
continue;
points[1][k++] = points[1][i];
px = points[1][i].x;
py = points [1][i].y;
if (LastX > 0)
{
line(image, Point(px, py), Point(LastX, LastY), Scalar(255, 0, 0), 5);
}
LastX = px;
LastY = py;
circle( image, points[1][i], 3, Scalar(0,255,0), -1, 8);
}
points[1].resize(k);
}
However, the line only appears in the current frame and the position of the line doesn't save in previous frames. Could someone please tell me what I'm doing wrong?