Ask Your Question
0

Results for matchtemplate are too high

asked 2020-06-12 05:40:39 -0500

Robix66 gravatar image

Hi,

I'm having some issues with MatchTemplate. When extracting the best position value with MinMaxLoc, it's always very high values (0.99 something), even when trying to match on an image where the pattern is absent. I think I never saw it lower than 0.96. So this is a bit painful when trying to filter false positives, because you end up setting the threshold to 0.997 because it was still having false positives at 0.996... And not be sure it will be enough.

Is it an expected behavior ? I read somewhere this value should not be used as a score, but it didn't explain why, and how to get a score then.

I'm thinking about doing something like that :

        if ((MatchingType == Emgu.CV.CvEnum.TemplateMatchingType.SqdiffNormed) ||
            (MatchingType == Emgu.CV.CvEnum.TemplateMatchingType.Sqdiff))
        {
            MatchLoc = MinLoc;
            Results.Confidence = (1 - MinVal) * 100;
        }
        else
        {
            MatchLoc = MaxLoc;
            Results.Confidence = MaxVal * 100;
        }

        Results.Confidence = Math.Max(0, Results.Confidence - 90) * 10;

        ((MatchTemplateResult)Results.Details).Center = new System.Windows.Point(MatchLoc.X + (ModelMatrix.Cols / 2), MatchLoc.Y + (ModelMatrix.Rows / 2));

But I'm not sure this is the right way or a good practice.

edit retag flag offensive close merge delete

Comments

I am noobie at template matching but what makes me wonder ist the if - else construct. Why not always

Results.Confidence = (1 - MinVal) * 100;

Or - if the result confidence is between 0-1 - which i assume:

Results.Confidence =  MinVal * 100;

But as i say - i dont know the api - maybe its not this straight forward. In the networks i am working with the confidence is always between 0-1.

holger gravatar imageholger ( 2020-06-23 06:23:43 -0500 )edit

For SqdiffNormed, the best value is the lowest one. For CcorrNormed and CcoeffNormed, it's the highest one. Hence the if/else to put them in the same way. All -Normed types give 0-1 values.

Robix66 gravatar imageRobix66 ( 2020-06-23 10:46:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-06-23 04:07:23 -0500

Robix66 gravatar image

So, it looks like using CcoeffNormed instead of CcorrNormed or SqdiffNormed gives more usable scores. I thought I already tried it but as I saw while trying again, it is easy to replace CcorrNormed by CcorrNormed if you are not fully paying attention.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-06-12 05:40:39 -0500

Seen: 252 times

Last updated: Jun 23 '20