2016-12-03 89 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。儘可能多地做到這一點。但我想第一種方法運行得更快,因爲它只需要一次掃描。

相關問題