Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Template Matching issue in video(object detection in frame by frame)

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, image description image description

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, image description

And frames with miss match, image description image description

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.