If you are using c++, cv::subtract give you a Mat with tons of pixels value but not a single value which tell you how many non zero pixels in the matrix. You can call countNonZero in c++ to count the number of non zero pixels.
auto const diff= img1 != img2;
if(countNonZero(dst) == 0){
cout<<"this is same picture"<<endl;
}else{
cout<<"this is not the same picture"<<endl;
}
You can use stl algorithm and iterator to do the comparison too. I do not know which one is faster, you better run some test on it.
bool const equal = std::equal(img1.begin<uchar>(), img1.end<uchar>(), img2.begin<uchar>());
If you want to compare similarity of images with different size, try out img_hash module of opencv_contrib.
Edit : I replace subtraction by comparison, it is easier to read and avoid the problem of value clip.