10

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?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
user1421108
  • 119
  • 2
  • 7

2 Answers2

7

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!

user1391128
  • 111
  • 2
4

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

Community
  • 1
  • 1
Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
  • 1
    Thanks for your rply .but I dont think it will work for a very small different ..suppose the source image contains two cars ....and the image to be compared also contains two same car...but one of the car has a red cross mark..it cannot detect that – user1421108 May 28 '12 at 12:27
  • 2
    sure it can. SIFT detects "corners", those points that are easy to recognize in any scale, any perspective, upside down, etc... I have used it with cluttered pictures and works really really fine. It is the state-of-the-art detector, together with fast. Just give it a try. What can be more difficult to detect than a picture of green grass on the grass. SIFT got no trouble – Jav_Rock May 28 '12 at 13:00
  • 1
    I have tried the comparison using SIFT descriptors and FlannBasedMatcher but it can not detect the uncommon part of the image... in a word it simply detects that both the images are same..Thanks a lot – user1421108 May 30 '12 at 09:24