比较BGR图像是否完全相同
Compare if BGR image is exactly the same
我正在尝试编写代码以找出两个图像是否相同。我能够将图像读为BGR
,并能够从另一个中减去图像。我需要进行检查,看看差异是否仅包含零。我知道有一个称为countNonZero
的函数,但仅在单个通道上起作用,而不是3个通道。我的解决方案是循环浏览整个矩阵并检查一切是否为零,但这太慢了。有没有有效的检查方法?这是我下面的代码。
int main(int argc, char** argv)
{
if(argc != 3)
{
printf("usage: DisplayImage.out <testImg.png> <copy.png>n");
return -1;
}
Mat image;
Mat copy;
Mat output;
image = imread(argv[1], 1);
copy = imread(argv[2], 1);
absdiff(image, copy, output);
if(countNonZero(output) == 0)
{
cout << "Same" << endl;
}
else
{
cout << "Different" << endl;
}
imshow("outut", output);
waitKey();
return 0;
}
您可以做到这一点:
Mat diff_im = image - copy;
double s = cv::sum(diff_im)[0];
您也可以使用norm类型NORM_L2
norm()
函数 double rst = cv::norm(img1, img2, cv::NORM_L2);
如果图像完全相同,则结果将为零。
越接近零。
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- 在C++STL中是否有Polyval(Matlab函数)等价物?
- 检查输入是否不是整数或数字
- 是否可以初始化不可复制类型的成员变量(或基类)
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 是否可以通过C++扩展强制多个python进程共享同一内存
- 此代码是否违反一个定义规则
- 是否需要删除包含对象的"pair"?
- 是否可以从int转换为enum类类型
- 无论条件是否为true,if总是在c++中执行
- 如何找到大小'x'数组是否完全填充,在C++?
- 检查值是否在集合p1和p2中,但不在p3中
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- 检查 std::shared_ptr<> 的当前底层类型是否为 T
- 在c++中检查长方体是否尽可能快地重叠(无迭代)
- GL_SHADERSTORAGE_BUFFER位置是否与其他着色器位置冲突
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 比较BGR图像是否完全相同
- 如何确定 BMP 图像是否包含来自标题的 BGR 或 BGRA 像素