Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find one image inside of another?

I have 2 bmp images. ImageA is a screenshot (example) ImageB is a subset of that. Say for example, an icon.

I want to find the X,Y coordinates of ImageB within ImageA (if it exists).

Any idea how I would do that?

like image 812
esac Avatar asked Mar 18 '10 18:03

esac


People also ask

How do I search for a photo of another picture?

That's a reverse image search. Google's reverse image search is a breeze on a desktop computer. Go to images.google.com(Opens in a new window), click the camera icon, and either paste in the URL for an image you've seen online, upload an image from your hard drive, or drag an image from another window.

How do I find the image of a website?

Search with an image from a website On your computer, go to the Chrome browser. Go to the website with the image you want to use. Right-click the image. Click Search Image with Google Lens to display results in a sidebar.


2 Answers

Here's a quick sample but it is slow take around 4-6 seconds, but it does exactly what you looking for and i know this post is old but if anyone else visiting this post recently you can look this thing you need .NET AForge namespace or framework google it and install it include AForge name space in your project and that's it it finds the pictiure with another and gives out the coordinates.

System.Drawing.Bitmap sourceImage = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\1.jpg");
            System.Drawing.Bitmap template = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\2.jpg");
            // create template matching algorithm's instance
            // (set similarity threshold to 92.1%)

           ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.921f);
                // find all matchings with specified above similarity

                TemplateMatch[] matchings = tm.ProcessImage(sourceImage, template);
                // highlight found matchings

           BitmapData data = sourceImage.LockBits(
                new Rectangle(0, 0, sourceImage.Width, sourceImage.Height),
                ImageLockMode.ReadWrite, sourceImage.PixelFormat);
            foreach (TemplateMatch m in matchings)
            {

                    Drawing.Rectangle(data, m.Rectangle, Color.White);

                MessageBox.Show(m.Rectangle.Location.ToString());
                // do something else with matching
            }
            sourceImage.UnlockBits(data);
like image 84
Mandah Mr. Avatar answered Oct 08 '22 03:10

Mandah Mr.


  1. So is there any warping of ImageB in ImageA?
  2. How "exact" are the images, as in, pixel-for-pixel they will be the same?
  3. How much computational power do you have for this?

If the answers to the first two questions are No and Yes, then you have a simple problem. It also helps to know the answer to Q3.

Update:

The basic idea's this: instead of matching a window around every pixel in imageB with every pixel in imageA and checking the correlation, let's identify points of interest (or features) in both images which will be trackable. So it looks like corners are really trackable since the area around it is kinda similar (not going into details) - hence, let's find some really strong corners in both images and search for corners which look most similar.

This reduces the problem of searching every pixel in B with A to searching for, say, 500 corners in B with a 1000 corners in A (or something like that) - much faster.

And the awesome thing is you have several such corner detectors at your disposal in OpenCV. If you don't feel using emguCV (C# varriant), then use the FAST detector to find matching corners and thus locate multiple features between your images. Once you have that, you can find the location of the top-left corner of the image.

like image 22
Jacob Avatar answered Oct 08 '22 05:10

Jacob