Matching template on video
Hi all,
I am a beginner in c + + and opencv, I try to apply this algorithm : http://answers.opencv.org/answers/18440/revisions/
to an object to be detected in a video, I change the code :
int main()
{
Mat scene = imread("c:\\scene.png");
Mat object = imread("c:\\object.png");
vector<Point> match_centers = tempMatch(object,scene,CV_TM_SQDIFF_NORMED,0.9);
drawMatch(object,scene,match_centers);
imshow("result",scene);
waitKey(0);
return 0;
}
by this :
int main()
{
Mat object = imread("C:\\object.png");
string filename = "C:\\video.flv";
VideoCapture cap(filename);
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
vector<Point> match_centers = tempMatch(object,frame,CV_TM_SQDIFF_NORMED,0.9);
drawMatch(object,frame,match_centers);
imshow("edges", frame);
if(waitKey(10) >= 0) break;
}
return 0;
}
In my modified code i try to match template in the video frame by frame trough the loop for, it work perfectly, the rectangle select the object to match when the object appear in the video, "my object is an ads sometime is appearing and sometime no".
The problem, when the object to match is not in the video the algorithme continues to draw rectangles i think because : draw Match(object,frame,match_centers); is in the loop, any ideas how i can fix that ?
Some image for more details :
1 - Video without algorithme applied :
2 - Here The code is looking for the template to match, as you see algorithm draw many rectangles and the object is not yet display, "I want to remove it" :
3 - Here the code is work and the object is matched :
Best regards!