title: How to match a set of contours with another set of contours
body: <p>Im trying to create a text matching application where I match the contours of 1 image with another one. I dont want to do OCR as I dont want to read the character, I just want to check if both contours are same like in the image below :</p>
  <p><a href="https://i.stack.imgur.com/8RuKp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8RuKp.jpg" alt="enter image description here" /></a>
  I tried to do it with template matching, but template matching doesnt work on an array of contours. I saved the contours points to an list and tried to use the list against a set of another list in template match.</p>
  <p>How can I match the contours of these 2 images and get a percentage of match?</p>
  <p>EDIT:</p>
  <p>As suggested by Jeru Luke, I tried the shape matching with all 3 matching types, but not getting proper result.</p>
  <p>Here is the code I used :</p>
  <pre><code>      private void ApplyShapeMatching()
      {
          try
          {
              listBox1.Items.Clear();
              var img = IMGDict[&quot;input&quot;].Clone();
              var imgSource = img.Convert&lt;Gray, byte&gt;()
                  .ThresholdBinaryInv(new Gray(50), new Gray(255));
              pictureBox3.Image = imgSource.ToBitmap();
  
              var imgTarget = imgtemplate.Convert&lt;Gray, byte&gt;()
                  .ThresholdBinaryInv(new Gray(50), new Gray(255));
              pictureBox4.Image = imgTarget.ToBitmap();
  
              VectorOfVectorOfPoint SourceContour = new VectorOfVectorOfPoint();
              Mat hier = new Mat();
              CvInvoke.FindContours(imgSource, SourceContour, hier, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
  
              VectorOfVectorOfPoint TargetContours = new VectorOfVectorOfPoint();
              Mat hier1 = new Mat();
              CvInvoke.FindContours(imgTarget, TargetContours, hier1, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
              ContoursMatchType type = new ContoursMatchType() ;
  
              if (comboBox1.SelectedIndex == 0)
              {
                type   = ContoursMatchType.I1;
              }
  
              if (comboBox1.SelectedIndex == 1)
              {
                  type = ContoursMatchType.I2;
              }
  
              if (comboBox1.SelectedIndex == 2)
              {
                  type = ContoursMatchType.I3;
              }
          
  
              for (int i = 0; i &lt; SourceContour.Size; i++)
              {
                  var distance = CvInvoke.MatchShapes( SourceContour[i] , TargetContours[i] , type);
  
              
                      var rect = CvInvoke.BoundingRectangle(SourceContour[i]);
  
                  if(distance &gt; 5.0)
                  {
                      img.Draw(rect, new Bgr(0, 0, 255), 2);
                  }
  
                  else
                  {
                      img.Draw(rect, new Bgr(0, 255, 0), 2);
                  }
                 
                  CvInvoke.PutText(img, distance.ToString(&quot;F6&quot;), new Point(rect.X, rect.Y + 20),
                          Emgu.CV.CvEnum.FontFace.HersheyPlain, 3, new MCvScalar(255, 0, 0));
                      listBox1.Items.Add(distance.ToString());               
              }
  
              pictureBox1.Image = img.ToBitmap();
  
          }
          catch (Exception ex)
          {
              throw new Exception(ex.Message);
          }
      }
  </code></pre>