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.
I am noobie at template matching but what makes me wonder ist the if - else construct. Why not always
Or - if the result confidence is between 0-1 - which i assume:
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.
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.