Link to home
Start Free TrialLog in
Avatar of George Ge
George Ge

asked on

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.
SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of George Ge
George Ge

ASKER

is there another way to do this ?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial