Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Results for matchtemplate are too high

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.