I have 2 cv::Mat array (with same size), and when I want to compare them (if identical), I used cv::compare
cv::compare(mat1,mat2,dst,cv::CMP_EQ);
Is there any function that return true/false?
I have 2 cv::Mat array (with same size), and when I want to compare them (if identical), I used cv::compare
cv::compare(mat1,mat2,dst,cv::CMP_EQ);
Is there any function that return true/false?
If you need to compare 2 cv::Mat by sizes, then you might check
if(mat1.size() == mat2.size())
//do stuff
else
//do other stuff
If you need to check if 2 cv::Mat are equal, you can perform the AND XOR operator and check if the result is a cv::Mat full of zeros:
cv::bitwise_xor(mat1, mat2, dst);
if(cv::countNonZero(dst) > 0) //check non-0 pixels
//do stuff in case cv::Mat are not the same
else
//do stuff in case they are equal
If you need to check if 2 cv::Mat are equal, you can perform the AND operator and check if the result is a cv::Mat full of zeros:
The AND operator is not the good one for this task. If a matrix is all 0, it will always return true regardless if the other matrix is all 0 or not.
The XOR must be used in this case.
Here the modified version of blackibiza code:
cv::bitwise_xor(mat1, mat2, dst);
if(cv::countNonZero(dst) > 0) //check non-0 pixels
//do stuff in case cv::Mat are not the same
else
//do stuff in case they are equal
This function returns true/false based on similarity (untested)
bool MyCompare(Mat img1, Mat img2)
{
int threshold = (double)(img1.rows * img1.cols) * 0.7;
cv::compare(img1 , img2 , result , cv::CMP_EQ );
int similarPixels = countNonZero(result);
if ( similarPixels > threshold ) {
return true;
}
return false;
}