public void FindImage()
 {
     rectangles = new List <Rectangle>();
     using (Image <Bgr, byte> imgSrc = BaseImage.Copy())
     {
         while (true)
         {
             using (Image <Gray, float> result = imgSrc.MatchTemplate(SubImage, TemplateMatchingType.CcoeffNormed))
             {
                 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;
                 }
             }
         }
     }
 }
 public void DrawRectanglesOnImage()
 {
     ResultImage = BaseImage.Copy();
     foreach (var rectangle in this.rectangles)
     {
         ResultImage.Draw(rectangle, new Bgr(Color.Blue), 1);
     }
 }
Пример #3
0
 public void MarkLocationsOnImage()
 {
     ResultImage = BaseImage.Copy();
     foreach (var pt in Points)
     {
         ResultImage.Draw(new Cross2DF(pt, 10, 10), new Bgr(Color.Red), 2);
     }
 }
Пример #4
0
        public void FindImage()
        {
            stopwatch = new Stopwatch();
            stopwatch.Start();

            var imgSrc = BaseImage.Copy();

            // FindImage all occurences of imgFind
            while (true)
            {
                using (Image <Gray, float> result = imgSrc.MatchTemplate(SubImage, TM_TYPE.CV_TM_CCOEFF_NORMED)) {
                    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] > Threashold)
                    {
                        // This is a match. Do something with it, for example draw a rectangle around it.
                        Rectangle match = new Rectangle(maxLocations[0], SubImage.Size);
                        Points.Add(new Point(maxLocations[0].X + SubImage.Size.Width / 2,
                                             maxLocations[0].Y + SubImage.Size.Height / 2));

                        // Fill the drawing with red in order to ellimate this as a source.
                        imgSrc.Draw(match, new Bgr(Color.Red), -1);

                        // Add the found rectangle to the results.
                        rectangles.Add(match);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            imgSrc.Dispose();
            stopwatch.Stop();
        }