Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare 2 cv::Mat [duplicate]

Tags:

c++

opencv

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?

like image 360
Quyền Anh Avatar asked Sep 04 '14 07:09

Quyền Anh


1 Answers

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
like image 136
madduci Avatar answered Sep 22 '22 00:09

madduci