Reinit goodFeaturesToTrack and LukasKanade optical flow.
Hi guys.. I am at the moment using goodFeaturesToTrack + Lukas kanade optical flow to track objects. When i lose the object (defined by bool) I have to reinitiate the goodFeaturesToTrack and LukasKanade optical flow. This might seem like a stupid question, and has indeed been for me for couple of weeks, but i cannot seems to perform the reinitiating stage. I clear the points i have been tracking.. Use goodFeatureToTrack on the new location of the mask, Lukas kanade to track the points.. I mark the the good features with a circle on the image, so in know that i started all over, but the seem to be spread as before which make me wonder if it actually is doing what it is supposed to do?
there is a lot of code.. i don't it scare you away..
else // performing reinit
{
Rect redetected;
redetected = box(gray);
cout << "i did it" << endl;
cout <<redetected.width <<" , " <<redetected.height << endl;
if(redetected.width<face.width)
{
Rect NewBOx;
NewBOx.x = backup_center.x-face.width/2;
NewBOx.y = backup_center.y-face.height/2/2;
NewBOx.width = face.width;
NewBOx.height = face.height;
face = NewBOx;
}
points[1].clear();
point_final.clear();
rectangle(image,face,Scalar(255,255,0));
imshow("test",image);
mask(face).setTo(Scalar(255));
vector<Point2f> tmp;
goodFeaturesToTrack(gray, tmp, MAX_COUNT, 0.01, 10, mask, 3, 0, 0.04);
cornerSubPix( gray, tmp, winSize, cvSize(-1,-1), termcrit);
points[1].push_back(tmp[0]);
calcOpticalFlowPyrLK(prevGray, gray, points[0], points[1], status, err, winSize, 3, termcrit, OPTFLOW_LK_GET_MIN_EIGENVALS, qualitylevel);
calcOpticalFlowPyrLK(gray, prevGray, points[1], point_final, status2, err2, winSize, 3, termcrit, OPTFLOW_LK_GET_MIN_EIGENVALS, qualitylevel);
}
I tried debugging, and can see that GoodFeaturesToTrack only adds one circle, which isn't nessesarly within the mask, how do i make it add more than one.. I doesn't make sense that it doesn't add more since i have deleted all previous points. ..
It's reinit stage only that seem to be troublesome.. Thanks in advance.
Problem solved..
I so much hate my life!!!
I still have problem making removing the old ones.. they still seems to appear, The circles don't get removed.
may be you can try tmp.clear() and after goodFeaturesToTrack(gray, tmp, MAX_COUNT, 0.01, 10, mask, 3, 0, 0.04); to track new points in your new image. There is a good sample in opencv/samples/lkdemo.cpp
I have seen that sample, it is kinda based on that.. the sample aren't capable of restarting which what I am trying to do..
In this sample you can reinit if you press keyboard c. Variable needToInit becomes true and vector point are clear and function goodFeaturesToTrack is called again. I don't know if it is this sort of reint you want.
Actually yeah.. But it has to applied to a mask. but that should be a problem.. I look into it.. thanks :)
I am actually doing the same thing as them.. weird though my circles don't get removed..