使用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、、、
相关推荐
橘子师兄6 分钟前
C++AI大模型接入SDK—ChatSDK封装
开发语言·c++·人工智能·后端
桂花很香,旭很美7 分钟前
基于 MCP 的 LLM Agent 实战:架构设计与工具编排
人工智能·nlp
Christo39 分钟前
TFS-2026《Fuzzy Multi-Subspace Clustering 》
人工智能·算法·机器学习·数据挖掘
五点钟科技17 分钟前
Deepseek-OCR:《DeepSeek-OCR: Contexts Optical Compression》 论文要点解读
人工智能·llm·ocr·论文·大语言模型·deepseek·deepseek-ocr
人工智能AI技术19 分钟前
【C#程序员入门AI】本地大模型落地:用Ollama+C#在本地运行Llama 3/Phi-3,无需云端
人工智能·c#
Agentcometoo28 分钟前
智能体来了从 0 到 1:规则、流程与模型的工程化协作顺序
人工智能·从0到1·智能体来了·时代趋势
工程师老罗31 分钟前
什么是目标检测?
人工智能·目标检测·计算机视觉
jarreyer32 分钟前
【AI 编程工具】
人工智能·编程工具
阿杰学AI34 分钟前
AI核心知识75——大语言模型之MAS (简洁且通俗易懂版)
人工智能·ai·语言模型·自然语言处理·agent·多智能体协作·mas
小程故事多_8036 分钟前
深度搜索Agent架构全解析:从入门到进阶,解锁复杂问题求解密码
人工智能·架构·aigc