Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV - Fastest method to check if two images are 100% same or not

Tags:

c++

python

opencv

There are many questions over here which checks if two images are "nearly" similar or not.

My task is simple. With OpenCV, I want to find out if two images are 100% identical or not.

They will be of same size but can be saved with different filenames.

like image 561
milan m Avatar asked Apr 21 '14 10:04

milan m


People also ask

How do I compare two images in OpenCV?

Use the norm() Function of OpenCV to Compare Images If the two images that we want to compare have the same size and orientation, we can use the norm() function of OpenCV. This function finds errors present in identical pixels of the two images.

Is Pil or cv2 faster?

Most of cases, cv2 method is faster than pil one.


1 Answers

the sum of the differences should be 0 (for all channels):

bool equal(const Mat & a, const Mat & b)
{
    if ( (a.rows != b.rows) || (a.cols != b.cols) )
        return false;
    Scalar s = sum( a - b );
    return (s[0]==0) && (s[1]==0) && (s[2]==0);
}
like image 55
berak Avatar answered Oct 27 '22 18:10

berak