0

I am new to image processing. My SO question is...

I take an image using a camera, then I use this image and check it against a list container. If the list container contains an image that looks like this image then do an operation, otherwise don't.

Example...

  1. I have one image "img_one"
  2. My list contains "image_one,image_two,image_three"
  3. Show list has image_one (i.e. it looks like this image)

So how do I check this image against the items in the list container and show which image looks like this image?

Thanks in advance friends. All ideas are appreciated.

Saravanan
  • 363
  • 1
  • 14
QuokMoon
  • 4,387
  • 4
  • 26
  • 50
  • @djaqeel in image processeing i have written – QuokMoon Mar 22 '13 at 12:10
  • possible duplicate of [Checking images for similarity with OpenCV](http://stackoverflow.com/questions/11541154/checking-images-for-similarity-with-opencv) – Sam Mar 22 '13 at 15:08

3 Answers3

3

It depends a lot on what do you define by "duplicate".

If you are looking for absolutely identical copies (copy-paste), the game is simple. The approach proposed by Safir, with just a few performance improvements, is Ok.

If you want to find almost-exact duplicates, the job suddenly becomes incredibly difficult. Check out this Checking images for similarity with OpenCV for more info.

Now, back to the "simple" approach, it depends on how many pictures you have to compare. Because comparing each image against all the others in a folder with 1000 images gives you 1.000.000 image reads and comparisons. (Because you cannot store them all in RAM at once, you will have to load and unload them a million times) That way is too much for even a powerful desktop processor.

A simple way would be to use a hashing function (as sha2) for each image, and then compare just the hashes. A good ad-hoc "hashing" for images may be the histogram (although for positives you may want to double-check with memcmp).

And even if you try the brute-force approach (comparing each image pixel with the other), a faster way is to use memcmp() instead of accessing images pixel by pixel.

Community
  • 1
  • 1
Sam
  • 19,708
  • 4
  • 59
  • 82
2

I don't think there exists such a function in opencv. You have to loop through the pixels yourself and check them one by one. A sample code can be like this:

bool identical(cv::Mat m1, cv::Mat m2)
{
  if ( m1.cols != m2.cols || m1.rows != m2.rows || m1.channels() != m2.channels() || m1.type() != m2.type() )
    {
      return false;
    }

  for ( int i = 0; i < m1.rows; i++ )
    {
      for ( int j = 0; j < m1.cols; j++ )
        {
          if ( m1.at(i, j) != m2.at(i, j) )
            {
              return false;
            }
        }
    }
  return true;
}

If you want to iterate a bit faster through all the pixels, you can look at OpenCV: Matrix Iteration.

Community
  • 1
  • 1
Safir
  • 902
  • 7
  • 9
-1

i think its little bit time consuming process to compare two images. but you can check it by comparing binaries of that images with each other from adapter or from where you are binding images with ListView.

Ajay
  • 1,189
  • 1
  • 12
  • 28