Image comparison method with C++ and OpenCV

6.8k Views Asked by At

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?

2

There are 2 best solutions below

3
On

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

0
On

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!