How do I compare two images & recognize the pattern in an image?

c# – How do I compare two images & recognize the pattern in an image? – Stack Overflow

You might be looking for this

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.5%)

       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);

I warn you it is quite slow takes around 6 seconds to process image of 1024×768 finding in it pciture with the size of 50×50.enter code here

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *

What is 8 + 6 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)