Can we check if a duplicate image exists in the list?

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

I take the image with the camera, then use this image and check it on the list container. If the list container contains an image similar to this image, perform the operation, otherwise not.

Example...

  • I have one image "img_one"
  • My list contains "image_one, image_two, image_three"
  • Show list has image_one (i.e. similar to this image)

So, how can I check this image for elements in the list container and show what image looks like this image?

Thanks in advance to friends. Any ideas are welcome.

0
source share
3 answers

It depends on what you define with "duplicate".

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

If you want to find near-exact duplicates, work suddenly becomes incredibly difficult. Check out this image check for similarities to OpenCV for more information.

Now, back to the β€œsimple” approach, it depends on how many pictures you need to compare. Since comparing each image with everyone else in a folder with 1000 images gives you 1,000,000 images and comparisons. (Since you cannot store them all in RAM at once, you will have to load and unload them a million times). This is too much for even a powerful desktop processor.

An easy way would be to use a hash function (like sha2) for each image, and then compare only the hashes. A good ad-hoc "hash" for images can be a histogram (although for positive results you can double check with memcmp).

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

+2
source

I do not think opencv has such a function. You must scroll the pixels yourself and check them one by one. An example code could be:

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 across all pixels, you can watch OpenCV: Matrix Iteration .

+1
source

I think this small process takes a long time to compare two images. but you can check it by comparing the binaries of these images to each other from the adapter or from where you link the images to the ListView.

-one
source

All Articles