how to check whether two matrices are identical in OpenCV

前端 未结 9 1791
南方客
南方客 2020-11-28 10:44

I have two instances of cv::Mat : m1 and m2. They are of the same numeric type and sizes. Is there any function in OpenCV that returns whether the matrices are identical (ha

9条回答
  •  囚心锁ツ
    2020-11-28 10:55

    For multichannel images, you could use cv::Mat::reshape to create a single channel image without any extra overhead.

    An update of Antonio's answer would be

    bool areEqual(const cv::Mat& a, const cv::Mat& b)
    {
        cv::Mat temp;
        cv::bitwise_xor(a,b,temp);
        return !(cv::countNonZero(temp.reshape(1)));
    }
    

提交回复
热议问题