使用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、、、
相关推荐
夏天是冰红茶2 小时前
DINO原理详解
人工智能·深度学习·机器学习
吴佳浩5 小时前
Python入门指南(六) - 搭建你的第一个YOLO检测API
人工智能·后端·python
SHIPKING3935 小时前
【AI应用开发设计指南】基于163邮箱SMTP服务实现验证登录
人工智能
yong99905 小时前
基于SIFT特征提取与匹配的MATLAB图像拼接
人工智能·计算机视觉·matlab
知秋一叶1236 小时前
Miloco 深度打通 Home Assistant,实现设备级精准控制
人工智能·智能家居
春日见6 小时前
在虚拟机上面无法正启动机械臂的控制launch文件
linux·运维·服务器·人工智能·驱动开发·ubuntu
————A6 小时前
强化学习----->轨迹、回报、折扣因子和回合
人工智能·python
CareyWYR7 小时前
每周AI论文速递(251215-251219)
人工智能
weixin_409383127 小时前
在kaggle训练Qwen/Qwen2.5-1.5B-Instruct 通过中二时期qq空间记录作为训练数据 训练出中二的模型为目标 第一次训练 好像太二了
人工智能·深度学习·机器学习·qwen
JoannaJuanCV7 小时前
自动驾驶—CARLA仿真(22)manual_control_steeringwheel demo
人工智能·自动驾驶·pygame·carla