Jump to content
alien

[C#] Finding an image in another image(using AForge)

Recommended Posts

This is a simple example using C# and AForge of how you can detect if ImageA is found in ImageB.

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

You can add it to you're project as a NuGet package or from their website

AForge.NET :: Computer Vision, Artificial Intelligence, Robotics

The code is very straight forward:

- you load to images(source and template)

- you create a ExhaustiveTemplateMatching from AForge

- you store the found matches in a TemplateMatch


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

foreach (TemplateMatch m in matchings)
MessageBox.Show(m.Rectangle.Location.ToString());

Working code can be found here: hg clone https://bitbucket.org/rokill3r/imageprocessing

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...