我正在使用Emgu网站上使用以下代码的教程中使用的代码:
using (Image<Gray, float> result = source.MatchTemplate(template, TemplateMatchingType.CcoeffNormed))
{
double[] minValues, maxValues;
Point[] minLocations, maxLocations;
result.MinMax(out minValues, out maxValues, out minLocations, out maxLocations);
// You can try different values of the threshold. I guess somewhere between 0.75 and 0.95 would be good.
if (maxValues[0] > 0.6)
{
// This is a match. Do something with it, for example draw a rectangle around it.
Rectangle match = new Rectangle(maxLocations[0], template.Size);
imageToShow.Draw(match, new Bgr(Color.Red), 3);
}
}
识别另一个图像内部的单个子图像非常有用。但是我想知道您将如何调整此代码以识别多个实例。
预先感谢。
您可以自己扫描'结果'图像,而不是使用minmax方法,以找到满足您病情的像素(例如Val> 0.6)。
或,在使用minmax找到最大值后,用"结果"中的0填充" maxLocation"像素,然后再次运行minmax。尽可能多地执行此操作。但是我猜第一个方法运行速度更快,因为它只需要一次扫描。