使用 Emgu CV 进行模板匹配 - 不适用于多个模板
Template matching using Emgu CV - not working for multiple templates
我正在处理 Emgu CV,我没有得到图像中多个模板的结果,请检查下面的代码,让我知道我在哪里犯了错误。
我相信我在 while 循环中犯了一个错误 - 请纠正我需要做些什么才能得到结果。
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;
}
}
}
}
它正在运行并更新了我已更改的评论中的代码。
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;
}
}
}
}
我正在处理 Emgu CV,我没有得到图像中多个模板的结果,请检查下面的代码,让我知道我在哪里犯了错误。 我相信我在 while 循环中犯了一个错误 - 请纠正我需要做些什么才能得到结果。
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;
}
}
}
}
它正在运行并更新了我已更改的评论中的代码。
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;
}
}
}
}