使用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、、、
相关推荐
LK_072 分钟前
【Agent】工具调用的安全边界:从模型输出到程序执行
人工智能·笔记·python·agent
土星云SaturnCloud2 分钟前
基于 PP-OCR 的车牌识别:从数据整理到土星云 SE110S 系列边缘部署
人工智能·ai·ocr·边缘计算
zz_nj3 分钟前
中兴微方案 MIFI
人工智能
打工仔折腾 AI5 分钟前
鸿蒙移动端直连 Windows 远程桌面配置与性能调优实践
人工智能·windows·后端·python·华为·性能优化·harmonyos
AI_work9 分钟前
43 号令下招投标全流程留痕分析:电子卷宗 15 年保存与投标人文档合规体系重构
大数据·人工智能·ai·重构
技灵AI21 分钟前
AI 开箱视频怎么做?用创意开场带出商品展示
人工智能·prompt·aigc
王亚博_Abel22 分钟前
AI 编程时代怎么选前端框架?同一个应用让 Agent 用 12 种框架各写 5 遍,我整理出这套选型方法
前端·人工智能·前端框架
低调小一26 分钟前
客户端开发者学 Eino(01):从一次模型调用理解 Agent 架构
人工智能·架构·eino
武汉星际互动34 分钟前
政务大厅软硬件升级改造怎么做?
人工智能·政务
IT_陈寒35 分钟前
Vite开发实战:从入门到精通
前端·人工智能·后端