Say I have a very simple image or shape such as this stick man drawing:
I also have a library of other simple images which I want to compare the first image to and determine the closest match:
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:
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.
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.
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.
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.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With