【发布时间】: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;
}
【问题讨论】: