使用OpenCV的absdiff函数报错

1.absdiff用法

absdiff函数用于计算两个输入图像之间每个像素的差异,并返回结果图像。

cpp 复制代码
void cv::absdiff 	( 	InputArray  	src1,
		InputArray  	src2,
		OutputArray  	dst 
	) 	

//eg:比较两图像的差异
/*
 cv::Mat diff;
 cv::absdiff(depLeft32, imDepth, diff);
*/

2.ERROR:

terminate called after throwing an instance of 'cv::Exception'

what(): OpenCV(4.2.0) ../modules/core/src/arithm.cpp:666: error: (-209:Sizes of input arguments do not match) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function 'arithm_op'

错误提示输入的两个矩阵应该有同样的大小和通道,所以把图像的大小打印出来。

cpp 复制代码
        cout << "depLeft32 info :" << depLeft32.rows << " " << depLeft32.cols << " " << depLeft32.channels() << endl;
        cout << "imDepth   info :" << imDepth.rows << " " << imDepth.cols << " " << imDepth.channels() << endl;
//.rows是输出图像的行,.cols是输出图像的列,.channels是输出图像的通道

发现图像大小是一样的,但是通道数不一样,使用cv::cvtColor()将通道数转换为一样

cpp 复制代码
//将三通道转换为单通道
cv::cvtColor(depLeft, depLeft, cv::COLOR_BGR2GRAY);
//将单通道转换为三通道则使用GRAY2BGR、GRAY2RGB、、、
相关推荐
weixin_46846685几秒前
支持向量机新手实战指南
人工智能·python·算法·机器学习·支持向量机
lzp07912 分钟前
从机器翻译到智驾:规则派的黄昏与数据革命的终局 (叁)
人工智能·自然语言处理·机器翻译
夕小瑶9 分钟前
Claude Code 保姆级上手教程(2026 版)
人工智能·python
心态与习惯27 分钟前
人工智能对管理科学与工程科研的冲击
人工智能·科研·读博·冲击·管科
sinat_2869451928 分钟前
gitnexus vs graphify
人工智能
Ztopcloud极拓云视角33 分钟前
Claude Opus 4.8 实战接入指南:动态工作流 + 思考投入控制深度使用
大数据·人工智能·gpt·claude·deepseek
cxr82837 分钟前
高分子复合材料 AI 逆向设计合—— 认知基座与理论框架
人工智能·材料逆向设计合成
落叶无情39 分钟前
第二章 ICEF核心知识解读 第二节 ICEF:从“规律驱动提示“到“世界规律认知操作系统“的范式跃迁
人工智能
逻辑君40 分钟前
Foresight研究报告【20260014】
人工智能·深度学习
FserSuN41 分钟前
Machine Learning Specialization - Week 1, 9-20学习总结
人工智能·学习·机器学习