Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenCV to recognise similar (not completely identical) simple images?

Say I have a very simple image or shape such as this stick man drawing:

enter image description here

I also have a library of other simple images which I want to compare the first image to and determine the closest match:

enter image description here

Notice that the two stick men are not completely identical but are reasonably similar.

I want to be able to compare the first image to each image in my library until a reasonably close match is found. If necessary, my image library could contain numerous variations of the same image in order to help decide which type of image I have. For example:

enter image description here

My question is whether this is something that OpenCV would be capable of? Has it been done before, and if so, can you point me in the direction of some examples? Many thanks for your help.

Edit: Through my searches I have found many examples of people who are comparing images, or even people that are comparing images which have been stretched or skewed such as this: Checking images for similarity with OpenCV . Unfortunately as you can see, my images are not just translated (Rotated/Skewed/Stretched) versions of one another - They actually different images although they are very similar.

like image 757
user1636130 Avatar asked Feb 02 '15 13:02

user1636130


People also ask

How do I compare two images in OpenCV?

Python - OpenCV & PyQT5 together To compare two images, we use the Mean Square Error (MSE) of the pixel values of the two images. Similar images will have less mean square error value. Using this method, we can compare two images having the same height, width and number of channels.

How can you tell if two pictures are the same?

First we check if they have the same size and channels. If they have the same sizes and channels, we proceed by subtracting them. The operation cv2. subtract(image1, image2) simply subtract from each pixel of the first image, the value of the corresponding pixel in the second image.

What is OpenCV template matching?

Template Matching is a method for searching and finding the location of a template image in a larger image. OpenCV comes with a function cv. matchTemplate() for this purpose.


2 Answers

You should be able to do it using feature template match function of OpenCV. You can use matchTemplate function to look for the feature and then, minMaxLoc to find its location. Check out the tutorial on OpenCV web site for matchTemplate.

like image 127
unxnut Avatar answered Sep 18 '22 03:09

unxnut


seems you need feature points detections and matching. Check these docs from OpenCV:

http://docs.opencv.org/doc/tutorials/features2d/feature_detection/feature_detection.html http://docs.opencv.org/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html

like image 36
iwlagn Avatar answered Sep 19 '22 03:09

iwlagn