Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you want to implement a "generic bitwise comparison" for cv::Mat you could write something like this:

// comparison function for two cv::Mats bool cvMat_EQ(const cv::Mat& data1, const cv::Mat& data2) {
bool success = true;

// check if is multy dimensional
if(data1.dims > 2 || data2.dims > 2)
{
  if( data1.dims != data2.dims || data1.type() != data2.type() )
  {
    return false;
  }

  for(int32_t dim = 0; dim < data1.dims; dim++){
    if(data1.size[dim] != data2.size[dim]){
      return false;
    }
  }
}
else
{
  if(data1.size() != data2.size() || data1.channels() != data2.channels() || data1.type() != data2.type()){
    return false;
  }
}

int nrOfElements = data1.total()*data1.elemSize1();

//bytewise comparison of data
int cnt = 0;
for(cnt = 0; cnt < nrOfElements && success; cnt++)
{
  if(data1.data[cnt] != data2.data[cnt]){
    success = false;
  }
}
return success;

}

If you want to implement a "generic bitwise comparison" for cv::Mat you could write something like this:

// comparison function for two cv::Mats bool cvMat_EQ(const cv::Mat& data1, const cv::Mat& data2) {
bool success = true;

// check if is multy dimensional
if(data1.dims > 2 || data2.dims > 2)
{
  if( data1.dims != data2.dims || data1.type() != data2.type() )
  {
    return false;
  }

  for(int32_t dim = 0; dim < data1.dims; dim++){
    if(data1.size[dim] != data2.size[dim]){
      return false;
    }
  }
}
else
{
  if(data1.size() != data2.size() || data1.channels() != data2.channels() || data1.type() != data2.type()){
    return false;
  }
}

int nrOfElements = data1.total()*data1.elemSize1();

//bytewise comparison of data
int cnt = 0;
for(cnt = 0; cnt < nrOfElements && success; cnt++)
{
  if(data1.data[cnt] != data2.data[cnt]){
    success = false;
  }
}
return success;

}

If you want to implement a "generic bitwise comparison" for cv::Mat you could write something like this:

 bool cvMat_EQ(const cv::Mat& data1, const cv::Mat& data2)
{ 
{ bool success = true;

true;
    // check if is multy dimensional
 if(data1.dims > 2 || data2.dims > 2)
{
    {
      if( data1.dims != data2.dims || data1.type() != data2.type() )
  {
    {
        return false;
  }

    }
      for(int32_t dim = 0; dim < data1.dims; dim++){
     if(data1.size[dim] != data2.size[dim]){
       return false;
    }
  }
}
    }
      }
    }
    else
{
    {
      if(data1.size() != data2.size() || data1.channels() != data2.channels() || data1.type() != data2.type()){
     return false;
  }
}

    }
    }
    int nrOfElements = data1.total()*data1.elemSize1();
  //bytewise comparison of data
 int cnt = 0;
 for(cnt = 0; cnt < nrOfElements && success; cnt++)
{
    {
      if(data1.data[cnt] != data2.data[cnt]){
     success = false;
  }
}
    }
    }
    return success;
  }

}

If you want to implement a "generic bitwise comparison" for cv::Mat you could write something like this:


bool cvMat_EQ(const cv::Mat& data1, const cv::Mat& data2)
{
    bool success = true;
    // check if is multy multi dimensional
    if(data1.dims > 2 || data2.dims > 2)
    {
      if( data1.dims != data2.dims || data1.type() != data2.type() )
      {
        return false;
      }
      for(int32_t dim = 0; dim < data1.dims; dim++){
        if(data1.size[dim] != data2.size[dim]){
          return false;
        }
      }
    }
    else
    {
      if(data1.size() != data2.size() || data1.channels() != data2.channels() || data1.type() != data2.type()){
        return false;
      }
    }
    int nrOfElements = data1.total()*data1.elemSize1();
    //bytewise comparison of data
    int cnt = 0;
    for(cnt = 0; cnt < nrOfElements && success; cnt++)
    {
      if(data1.data[cnt] != data2.data[cnt]){
        success = false;
      }
    }
    return success;
  }