Emgu find image a in image b

I am new to emgu and would like to advise where to start.

I looked at the definition of the form, but its too complicated for what I need. I think .. and my example of a surfer does not work. I get this error:

Can't get the SURF example in EMGU.CV to work?

In any case, this is what I would like to do: Find image A in image B. Image A is a simple square that always has the same series with 1 pixel frame and always the same size (I think), but the inner color may be black or one of about 7 other colors (solid color only). I need to find the coordinates of image A in image b when I press the button. see images below.

Image B

image b

and

Image A

image a

+7
source share
2 answers

Goosebumps answer is correct, but I thought a bit of code might be helpful. This is my code using MatchTemplate to detect a pattern (image A) inside the original image (image B). As Goosebumps noted, you probably want to include a gray color around the pattern.

 Image<Bgr, byte> source = new Image<Bgr, byte>(filepathB); // Image B Image<Bgr, byte> template = new Image<Bgr, byte>(filepathA); // Image A Image<Bgr, byte> imageToShow = source.Copy(); using (Image<Gray, float> result = source.MatchTemplate(template, Emgu.CV.CvEnum.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] > 0.9) { // 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); } } // Show imageToShow in an ImageBox (here assumed to be called imageBox1) imageBox1.Image = imageToShow; 
+19
source

You could take a look at http://docs.opencv.org/doc/tutorials/imgproc/histograms/template_matching/template_matching.html This is probably what you are looking for. Your black square will be a pattern. You can also try to include a little gray around it. This will prevent the detector from leaking into large black areas.

+3
source

All Articles