Search code examples
c#image-processingcomputer-visionpattern-matchingaforge

C# AForge pattern matching very low accuracy - what I'm doing wrong?


I need to find objects on images, so I'm trying to do it with AForge library. I've started with very simple pattern and picture, but recognition accuracy is awful already. I'm using ExhaustiveTemplateMatching:

ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0);
Bitmap img = new Bitmap("C:/img.bmp");
Bitmap pat = new Bitmap("C:/pat.bmp");
TemplateMatch[] matchings = tm.ProcessImage(img, pat);
Debug.WriteLine("Similar: " + matchings[0].Similarity);

That's my pattern:

Pattern

That's my image (it's just rotated pattern). It gets only 0,7400396 similarity:

Image1

This is practically equal to pattern's similarity to black square (0,7373355):

Image2

What I'm doing wrong, getting so low accuracy? How can I improve it?


Solution

  • You're expecting this function to perform object recognition, but that's not what it's designed to do. It literally just scans the images and compares pixel values directly in order to calculate similarity. It does not look for key features, handle rotation, scaling, etc... It looks for an exact duplicate of your template image.