Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image comparison method with C++ and OpenCV

I am new to OpenCV. I would like to know if we can compare two images (one of the images made by photoshop i.e source image and the otherone will be taken from the camera) and find if they are same or not. I tried to compare the images using template matching. It does not work. Can you tell me what are the other procedures which we can use for this kind of comparison?

like image 574
user1421108 Avatar asked May 28 '12 06:05

user1421108


People also ask

How do I compare two images in OpenCV?

We'll be using compare_ssim (from scikit-image), argparse , imutils , and cv2 (OpenCV). We establish two command line arguments, --first and --second , which are the paths to the two respective input images we wish to compare (Lines 8-13).

Can OpenCV be used for image classification?

OpenCV can be utilised to solve image classification problems. The OpenCV library offers a Deep Neural Network (DNN) module, which facilitates the use of deep learning related functions within OpenCV.

How do you compare two images for similarity?

The similarity of the two images is detected using the package “imagehash”. If two images are identical or almost identical, the imagehash difference will be 0. Two images are more similar if the imagehash difference is closer to 0.

How can I quantify difference between two images?

You can compare two images using functions from PIL. The diff object is an image in which every pixel is the result of the subtraction of the color values of that pixel in the second image from the first image. Using the diff image you can do several things. The simplest one is the diff.


2 Answers

Comparison of images can be done in different ways depending on which purpose you have in mind:

  • if you just want to compare whether two images are approximately equal (with a few luminance differences), but with the same perspective and camera view, you can simply compute a pixel-to-pixel squared difference, per color band. If the sum of squares over the two images is smaller than a threshold the images match, otherwise not.
  • If one image is a black-white variant of the other, conversion of the color images is needed (see e.g. http://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale). Afterwarts simply perform the step above.
  • If one image is a subimage of the other, you need to perform registration of the two images. This means determining the scale, possible rotation and XY-translation that is necessary to lay the subimage on the larger image (for methods to register images, see: Pluim, J.P.W., Maintz, J.B.A., Viergever, M.A. , Mutual-information-based registration of medical images: a survey, IEEE Transactions on Medical Imaging, 2003, Volume 22, Issue 8, pp. 986 – 1004)
  • If you have perspective differences, you need an algorithm for deskewing one image to match the other as well as possible. For ways of doing deskewing look for example in http://javaanpr.sourceforge.net/anpr.pdf from page 15 and onwards.

Good luck!

like image 190
user1391128 Avatar answered Oct 01 '22 05:10

user1391128


You should try SIFT. You apply SIFT to your marker (image saved in memory) and you get some descriptors (points robust to be recognized). Then you can use FAST algorithm with the camera frames in order to find the coprrespondent keypoints of the marker in the camera image. You have many threads about this topic:

How to get a rectangle around the target object using the features extracted by SIFT in OpenCV

How to search the image for an object with SIFT and OpenCV?

OpenCV - Object matching using SURF descriptors and BruteForceMatcher

Good luck

like image 36
Jav_Rock Avatar answered Oct 01 '22 04:10

Jav_Rock