我正在尝试使用以下代码在图像的某个位置应用 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);
执行 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
您对可能出现的问题有什么建议吗? 这个问题我纠结了好久……
谢谢。
最佳答案
简单。两张图片中要合并的 channel 数不同。
cvtColor(devilROI, canny, CV_RGB2GRAY);
正在拍摄您的 3 channel 图像并将其转换为 1 channel 灰度图像。您需要相同数量的 channel 才能使用 addWeighted
关于c++ - OpenCV - 输入参数的大小不匹配 - addWeighted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888388/