i am working on Emgu CV and i am not getting the result for multiple templates within an image, please check the below code and let me know where i am making a mistake. i believe i have made a mistake at while loop- kindly correct me what i need to do to get the results.
using (Image<Bgr, byte> imgSrc = BaseImage.Copy())
{
while (true)
{
using (Image<Gray, float> result = imgSrc.MatchTemplate(SubImage, TemplateMatchingType.SqdiffNormed))
{
CvInvoke.Threshold(result, result, 0.7, 1, ThresholdType.ToZero);
double[] minValues, maxValues;
Point[] minLocations, maxLocations;
result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
if (maxValues[0] > Threashold)
{
Rectangle match = new Rectangle(maxLocations[0], SubImage.Size);
imgSrc.Draw(match, new Bgr(Color.Blue), -1);
rectangles.Add(match);
}
else
{
break;
}
}
}
}
it is working and updated the code in comment which i have changed.
using (Image<Bgr, byte> imgSrc = BaseImage.Copy())
{
while (true)
{
//updated and changed TemplateMatchingType- CcoeffNormed.
using (Image<Gray, float> result = imgSrc.MatchTemplate(SubImage, TemplateMatchingType.CcoeffNormed))
{
CvInvoke.Threshold(result, result, 0.7, 1, ThresholdType.ToZero);
double[] minValues, maxValues;
Point[] minLocations, maxLocations;
result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
if (maxValues[0] > Threashold)
{
Rectangle match = new Rectangle(maxLocations[0], SubImage.Size);
imgSrc.Draw(match, new Bgr(Color.Blue), -1);
rectangles.Add(match);
}
else
{
break;
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.