Ask Your Question
0

How to find co-ordinates of matched tampletes on source image

asked 2018-12-28 06:44:09 -0600

manoharsonwan gravatar image

updated 2018-12-28 06:47:29 -0600

berak gravatar image

I have used multiple templates matching on OpenCV, and I am getting 6 matches on the source image after that I want to find out the coordinates of all matched templates which is in a rectangular form. So I want 4 x and y coordinates for each matched template. I have used the same code on OpenCV provides for multiple template matching.

Thank You It will be very helpful, I have been working on it for one month

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-12-28 06:57:47 -0600

LBerger gravatar image

In matchTemplate functions you can normalized output results

    normalize(results     , results     ,1,0,NORM_MINMAX);
    results .convertTo(img, CV_8U, 255);

then you can thresh results image and find connected components :

threshold(img, dst, thresh, 255, THRESH_BINARY);

connectedComponentsWithStats(dst, labels, stats, centroids, 8);
if (centroids.rows < 10)
{
    cout << "**********************************************************************************\n";
    for (int i = 0; i < centroids.rows; i++)
    {
        cout << dst.cols - centroids.at<double>(i, 0)  << " ";
        cout << dst.rows -  centroids.at<double>(i, 1)  << "\n";
    }
    cout << "----------------------------------------------------------------------------------\n";
}

A full example is here (colorMatchTemplate)

edit flag offensive delete link more

Comments

could you write in Python?. Thank you for your quick response

manoharsonwan gravatar imagemanoharsonwan ( 2018-12-28 07:09:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-12-28 06:44:09 -0600

Seen: 477 times

Last updated: Dec 28 '18