title: OpenCv: Finding multiple matches
body: <p>I have the following, but I can't figure out how to find ALL the matches in a source image.</p>
  
  <pre><code>    static void Main()
      {
          using (var template = Cv.LoadImage(@"images\logo.png", LoadMode.GrayScale))
          using (var source = Cv.LoadImage(@"images\manyLogos.png", LoadMode.GrayScale))
          using (var sourceColour = Cv.LoadImage(@"images\manyLogos.png", LoadMode.Color))
          {
              var width = source.Width - template.Width + 1;
              var height = source.Height - template.Height + 1;
              using (var result = Cv.CreateImage(Cv.Size(width, height), BitDepth.F32, 1))
              {
                  Cv.MatchTemplate(source, template, result, MatchTemplateMethod.SqDiff);
                  var THRESHOLD = 0.08D;
  
                  double minVal, maxVal;
                  CvPoint minLoc, maxLoc;                    
                  Cv.MinMaxLoc(result, out minVal, out maxVal, out minLoc, out maxLoc);
  
                  var outlineColor = (minVal &gt; THRESHOLD) ? CvColor.Green : CvColor.Red;
                  Cv.Rectangle(sourceColour, Cv.Point(minLoc.X, minLoc.Y), Cv.Point(minLoc.X + template.Width, minLoc.Y + template.Height), outlineColor, 1, 0, 0);
              }
  
              using (var window = new CvWindow("Test"))
              {
                  while (CvWindow.WaitKey(10) &lt; 0)
                  {
                      window.Image = sourceColour;
                  }
              }
          }
      }
  </code></pre>
  
  <p>I can outline the best match, just not all the matches.  I need to get all the matches somehow.</p>