【问题标题】:OpenCV - Sizes of input arguments do not match - addWeightedOpenCV - 输入参数的大小不匹配 - addWeighted
【发布时间】:2012-01-17 00:50:48
【问题描述】:

我正在尝试使用以下代码在图像的某个位置应用 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错误:输入参数的大小不匹配(操作既不是'array op array'(其中数组具有相同的大小和相同的通道数),也不是'array op scalar',也不是'scalar op array') arithm_op,文件 C:\OpenCV2.3\opencv\modules\core\src\arithm.cpp,第 1227 行 在抛出 'cv::Exception' 的实例后调用终止 what(): C:\OpenCV2.3\opencv\modules\core\src\arithm.cpp:1227: error: (-209) 该操作既不是“数组运算数组”(其中数组具有相同的大小和相同的通道数),也不是函数 arithm_op 中的“array op scalar”,也不是“scalar op array”

您对可能出现的问题有什么建议吗? 这个问题我纠结了好久……

谢谢。

【问题讨论】:

  • 哪一行特别抛出错误? -- 不用担心,我看到是addWeighted
  • @mathematical.coffee addWeighted,编辑了问题。谢谢。

标签: c++ opencv


【解决方案1】:

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

cvtColor(devilROI, canny, CV_RGB2GRAY);

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

【讨论】:

    【解决方案2】:

    好的,我想我明白了。

    我尝试使用 Mat::copyTo,然后我得到了:

     (scn ==1 && (dcn == 3 || dcn == 4))
    

    错误。

    然后我找到了this Stackoveflow 话题,这让我想到了转换回 RGB 的想法,然后我尝试了以下方法,它成功了:

    Mat devilROI = img(Rect(r->x+lowerRect.x, 
                            r->y + lowerRect.y, 
                            lowerRect.width, 
                            lowerRect.height));
    Mat canny;
    cvtColor(devilROI, canny, CV_BGR2GRAY);
    Canny(canny, canny, low_threshold, high_threshold);
    cvtColor(canny, canny, CV_GRAY2BGR);
    addWeighted(devilROI, 1.0, canny, 0.3, 0., devilROI);
    

    所以,如果有人有任何其他建议,我将不胜感激。

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      相关资源
      最近更新 更多