OpenCV - 输入参数的大小不匹配 - addWeighted

mrc*_*ori 14 c++ opencv

我试图使用以下代码在图像的某个位置应用Canny运算符:

//region of interest from my RGB image
Mat devilROI = img(Rect(r->x+lowerRect.x, 
                        r->y + lowerRect.y, 
                        lowerRect.width, 
                        lowerRect.height));
Mat canny;
//to grayscale so I can apply canny
cvtColor(devilROI, canny, CV_RGB2GRAY);
//makes my region of interest with Canny
Canny(canny, canny, low_threshold, high_threshold);
//back to the original image
addWeighted(devilROI, 1.0, canny, 0.3, 0., devilROI);
Run Code Online (Sandbox Code Playgroud)

执行addWeighted时,它会给我以下错误:

OpenCV Error: 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 arithm_op, file C:\OpenCV2.3\ opencv\modules\core\src\arithm.cpp, line 1227
terminate called after throwing an instance of 'cv::Exception'
what():  C:\OpenCV2.3\opencv\modules\core\src\arithm.cpp:1227: error: (-209) 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

你对这个问题有什么建议吗?我已经坚持了很久......

谢谢.

joh*_*jik 14

简单.您要合并的2个图像中没有相同数量的通道.

cvtColor(devilROI, canny, CV_RGB2GRAY);
Run Code Online (Sandbox Code Playgroud)

拍摄3通道图像并将其转换为1通道灰度图像.您需要使用相同数量的频道才能使用addWeighted