如何在OpenCV中检查两个矩阵是否相同 [英] how to check whether two matrices are identical in OpenCV

查看:64
本文介绍了如何在OpenCV中检查两个矩阵是否相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个cv :: Mat实例:m1和m2.它们具有相同的数字类型和大小. OpenCV中是否有任何函数可以返回矩阵是否相同(所有值都相同)?

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 (have all the same values)?

推荐答案

如Acme所述,您可以使用 !=运算符来调用cv::compare :

As mentioned by Acme, you can use cv::compare although it is not as clean as you might hope.
In the following example, cv::compare is called by using the != operator:

// Get a matrix with non-zero values at points where the 
// two matrices have different values
cv::Mat diff = a != b;
// Equal if no elements disagree
bool eq = cv::countNonZero(diff) == 0;

大概通过比较元素来迭代会更快吗?如果知道类型,则可以使用STL 等于函数:

Presumably it would be quicker to just iterate through comparing the elements though? If you know the type you could use the STL equal function:

bool eq = std::equal(a.begin<uchar>(), a.end<uchar>(), b.begin<uchar>());

这篇关于如何在OpenCV中检查两个矩阵是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆