【问题标题】:OpenCV - absdiff with a maskOpenCV - 带面具的 absdiff
【发布时间】:2020-02-10 18:15:08
【问题描述】:

我正在尝试使用蒙版计算两个图像的绝对差异,因此在计算差异时只考虑图像的一个区域。但是 OpenCV 在its function 中没有掩码部分。我看到了this question,但对我不起作用。我正在尝试将结果乘以掩码,以便只保留指定的区域。

代码:

Mat region = //a grayscale image containing a region of 255 and the rest is zero
Mat img1, img2 = //two images of the same size as the region image and of type CV_8UC1
Mat mask = region / 255; //to make a binary mask
Mat difference = Mat::zeros(region .rows, region .cols, CV_8UC1);

cv::absdiff(img1, img2, difference);
difference = difference * mask;
if (!difference.empty()) imshow("difference", difference);

当我尝试这个时,我得到一个错误。

错误:

错误:在 cv::gemm 中断言失败 (a_size.width == len)

发生在这里:

inline
Mat& Mat::operator = (const MatExpr& e)
{
    e.op->assign(e, *this);
    return *this;
}

【问题讨论】:

    标签: c++ opencv mask mat


    【解决方案1】:

    difference * mask表示你正在执行Matrix multiplication,这种情况下高度差必须与掩码宽度相同,如果你想执行Element wise multiplication你应该调用difference.mul(mask)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-02
      • 2018-12-07
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多