how to check whether two matrices are identical in OpenCV(如何在 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 虽然它不像你希望的那么干净."noreferrer">
在以下示例中,使用 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 equal 函数:
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 中检查两个矩阵是否相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 OpenCV 中检查两个矩阵是否相同
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
