Ask Your Question

dagotaa's profile - activity

2014-06-18 15:25:06 -0600 commented answer Matching template on video

I tried to put :

vector<Point> res; res.size() == 0;

before : if ( match_centers.size() > 0 ) drawMatch(object,frame,match_centers);

But, it does not work :(

2014-06-18 14:05:18 -0600 commented answer Matching template on video

Thank you for your response, How i can reset the vector to size 0 ? I tried with res.size() == 0 but same problem ... i think res is the name of my vector but i'am not sure.

Thank you again!

2014-06-18 13:23:25 -0600 asked a question 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 :

image description

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" :

image description

3 - Here the code is work and the object is matched :

image description

Best regards!