Hi,
I am working with multiple object detection application, as part of this I am trying to detect two of the objects using Template Matching method. I have cropped two templates in video for further process. Below are the templates,
First template is railway track separater, second one is switches placed next to track. I am trying to detect this two in source video while video file is running frame by frame in loop.
My application detecting two templates when they appear in frame. The problem is even though both templates disappear from frame, still application detecting some area. Below is the frame with expected result,
And frames with miss match,
Could any one help me to overcome this problem.
I just want to detect the objects with respect to providing templates in video. I don't want to track the objects. Below is the code I have used, //utility functions Mat TplMatch( Mat &img, Mat &mytemplate/vector<mat>temp/) { Mat result; matchTemplate( img, mytemplate/temp/, result, CV_TM_CCOEFF_NORMED ); normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() ); return result; }
//Localizing the best match with minMaxLoc
Point minmax( Mat &result )
{
double minVal, maxVal;
Point minLoc, maxLoc, matchLoc;
minMaxLoc( result, &minVal, &maxVal, &minLoc, &maxLoc, Mat() );
matchLoc = maxLoc;
//cout<<"minVAl of temp:"<<minVal<<"maxVAl of temp:"<<maxVal<<endl;
return matchLoc;
}
//in Main function(inside loop)
Mat temp = imread("temp.png", 1);
Mat result = TplMatch( videoFeed, temp);
Point match = minmax(result);
rectangle(videoFeed, match, Point(match.x + temp.cols , match.y + temp.rows), Scalar(0,255,0), 3);
help me to overcome this problem. Help would be appreciated greatly.
Regards.