How to recognize image A in image B in c#

Hello programmers.  I need a liitle Help in Windows Forms. I want to write a Code that returns true if Bitmap Image A is in Bitmap Image B. For Example : B = Screenshoot   and   A = little Part of Screenshot(Icon) .  Programm return True if B contains A and returns False if it isn't. Have anyone Idea how to do this.
I have found a Code in Internet but havenn't understand how it works :

public class BitmapExtensions
    {
        public bool Contains(this Bitmap template, Bitmap bmp)
        {
            const int divisor = 4;
            const int epsilon = 10;

            ExhaustiveTemplateMatching etm = new ExhaustiveTemplateMatching(0.9f);

            TemplateMatch[] tm = etm.ProcessImage(new ResizeNearestNeighbor(template.Width / divisor, template.Height / divisor).Apply(template),
                                                  new ResizeNearestNeighbor(bmp.Width / divisor, bmp.Height / divisor).Apply(bmp));
            if (tm.Length == 1)
            {
                Rectangle tempRect = tm[0].Rectangle;

                if(Math.Abs(bmp.Width / divisor - tempRect.Width) < epsilon && Math.Abs(bmp.Height / divisor - tempRect.Height) < epsilon)
                {
                    return true;
                }
            }
            return false;
        }
    }

Have any one Idea how to solve my problem.
George GeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
hmm..

AForge.NET Framework is a C# framework designed for developers and researchers in the fields of Computer Vision and Artificial Intelligence - image processing, computer vision, neural networks, genetic algorithms, machine learning, etc.

??
1
George GeAuthor Commented:
is there another way to do this ?
0
Miguel OzSoftware EngineerCommented:
It seems that your are using AForge.NET library in the sample, but the code samples I saw before use the bitmaps directly as shown below.
Parameter: 2 Bitmaps object to compare: large (screenshot) and small(little Part of Screenshot)
Code explanation: see comments
        private bool CompareBitmaps(Bitmap largeImage, Bitmap smallImage)
        {
            // create template matching algorithm instance (set similarity threshold to 90%)
            ExhaustiveTemplateMatching etm = new ExhaustiveTemplateMatching(0.9f);

            // find all matches with specified similarity
            TemplateMatch[] matches = etm.ProcessImage(largeImage, smallImage);

            if (matches.Length > 0)
            {
                //Print the first match details including where the match location coordinates are, you could add extra logic for specific location as per your original code but for comparing is all you need.
                TemplateMatch match = matches[0];
                Console.WriteLine("Match found at X: " +
                    match.Rectangle.Location.X + "; Y:" +
                    match.Rectangle.Location.Y);
                return true;
            }
            else
            {
                 return false;
           }
        }

Open in new window

Notes:
1) AForge imaging llibrary is available in NUGET.
2) How to get Bitmap:
 Bitmap largeImage = (Bitmap)Bitmap.FromFile("largeFileName path");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.