Match an image to desktop using AForge library

Costas

Administrator
Staff member
JavaScript:
//src - https://bitbucket.org/rokill3r/imageprocessing/src/default/ImageProcessing/Form1.cs
//or https://rstforums.com/forum/topic/47812-c-finding-an-image-in-another-imageusing-aforge/

System.Drawing.Bitmap sourceImage = (Bitmap)Bitmap.FromFile(SourceInput.Text);
System.Drawing.Bitmap template = (Bitmap)Bitmap.FromFile(TempateInput.Text);
// 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)
	MessageBox.Show(m.Rectangle.Location.ToString());

sourceImage.UnlockBits(data);

ref - http://www.aforgenet.com/

todo : use CopyFromScreen (take a screenshot whole screen), find the target image to.
 
Top