0

i wonder how can we compare columns of two mats

here is what am doing

 cv::Mat M(2,2, CV_8UC3, cv::Scalar(0,0,255));
 cv::Mat M2(2,2, CV_8UC3, cv::Scalar(0,0,255));

 for(int c = 0; c < M.cols; c++ ){
     if( M.col(c) == M2.col(0) ){   // error

     }

 }

am getting error

error: no viable conversion from 'cv::MatExpr' to 'bool'

so how to compare columns as i have to stich two images for which i need to do comparison column wise , so that when i attach 2nd image with 1st image , i want to make sure that i attach it position where last column of 1st image is equal to somewhere in 2nd image so that duplicate portion is eliminated.

1 Answer 1

2

You can check if two matrix are identical as explained here.

You can pass the columns instead of the whole matrix:

bool are_equal(const cv::Mat& a, const cv::Mat& b)
{
    return (cv::sum(a != b) == cv::Scalar(0, 0, 0, 0));
}


int main()
{
    cv::Mat3b a(3, 3);
    cv::Mat3b b(3, 3);

    cv::randu(a, 0, 9);
    cv::randu(b, 0, 9);

    bool same_columns = are_equal(a.col(1), b.col(2));      
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.