自学内容网 自学内容网

使用OpenCV的absdiff函数报错

1.absdiff用法

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

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'

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

        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()将通道数转换为一样

//将三通道转换为单通道
cv::cvtColor(depLeft, depLeft, cv::COLOR_BGR2GRAY);
//将单通道转换为三通道则使用GRAY2BGR、GRAY2RGB、、、


原文地址:https://blog.csdn.net/qq_62964142/article/details/140289899

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!