Comparing an image with a pattern one

Hi everyone!

As the title suggest, i need to compare an image (could be from the live feed of a camera) with a few patterns in memory, and be able to tell if this image is like one of the patterns (and wich) and hopefully the “mach level”.

So, i know that i have to sort some things, but the one that really mess me its the image comparison, i mean if the object it’s not in the exact same position than the pattern, it just complicates things, but where should i start? i mean, what should my bases be to be able to do this?

Thaks everyone for reading, i just hope that i made my self clear and if more info is needed just ask.

1 Like

Well, you’ve found a tricky problem. Trying to match an image and a pattern by moving and at worst case scaling and rotating them to find similarities is very time consuming. So you need to have another approach.

Luckily on the last university course they presented us some metrics that can be used describe textures on the image or pattern. Suppose that similarity in texture metric is enough to tell that image matches the pattern. Anyway using Grey Level Co-occurrence Matrix (GLCM) could be solution. It’s fast to calculate and use. There’s a very good document that describes how it’s calculated and used https://prism.ucalgary.ca/handle/1880/51900 or just download it https://prism.ucalgary.ca/bitstream/handle/1880/51900/texture%20tutorial%20v%203_0%20180206.pdf?sequence=11&isAllowed=y

1 Like

Can you explain your actual application – do you want it to recognize a banana or a car, or identify which chess piece you are holding, or follow a red ball or a marker? Your actual specific need matters a lot with these kinds of problems.

BoofCV can do template matching – but it method probably not going to work for your needs (depending on what they are)

If you want robust general object detection based on YOLO, then you could try using this tutorial for Processing+opencv:

http://www.magicandlove.com/blog/2018/08/08/darknet-yolo-v3-testing-in-processing-with-the-opencv-dnn-module/

see for example: Conflicting libraries (YOLO comp vision) - #7 by TTG

Thanks both for your answers. I need is to recognize (based on previous images) the drilling on a wooden piece, it needs to be able to tell (based on previous data) if it is a left or right door based only in the drilling (the drilling isn’t reversible).

I’ll check the links, and again thanks a lot

Maybe try BoofCV lib for Processing and SURF ?

https://boofcv.org/index.php?title=Performance:SURF

@erwrow forget the link I mentioned. Those methods work when you want separation between different kind of structures (like straight line vs zigzag line). Sounds like you are looking at separation of placement and set up of drill holes. I would try to create a set of numbers that describe the placement of holes and their relation to each other. Those numbers can be independent of scale and angle of the image. Comparing a set of numbers is immensly faster than comparing images

Thank for your tips Yes New feature is good for searching.

I see, so i should set a set of numbers to the control image, then recognice the drilling holes and then, with the same formula/function, get the set of numbers that resolves that set of drilling holes and compare with the control?

For example, the formula/function, could be the distance between some holes as 1, then if the distance between other holes is 1 (because the distance between holes are all the same, except for the ones that are different), then its is one drilling or the other

Yes, something like that. Measurements (numbers) should clearly separate right and left side. One way to check it is Principal Component Analysis (PCA). Afew links to implementations https://stackoverflow.com/questions/10604507/pca-implementation-in-java. If it gives two distinct groups for left and right side then you have good set of numbers that will work. Machine learning methods like k Nearest Neighbour (kNN) or support vector machine (SVM) should work fine. Here’s one implementation of kNN https://medium.com/@equipintelligence/java-algorithms-the-k-nearest-neighbor-classifier-4faca7ad26b2.

How ever if groups don’t separate nicely there will be false classifications. How accurate system needs to be? If you need 100% accuracy then you may need to tweak measurements until you get 100%.