2016-12-03 88 views
0

我使用使用过的教程Emgu的网站上用下面的代码的代码:EmguCV/Open CV - 有没有办法多次搜索模板子代码?

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); 
      } 
     } 

它的伟大工程,以确定其他图像内的单个子图像。但我想知道如何去适应这个代码来识别多个实例。

在此先感谢。

回答

0

您可以自己扫描“结果”图像,而不是使用MinMax方法来查找满足条件的像素(例如val> 0.6)。

或者,在用MinMax找到最大值后,在'result'中用'0'填充'maxLocation'像素并再次运行MinMax。尽可能多地做到这一点。但我想第一种方法运行得更快,因为它只需要一次扫描。

相关问题