gpt4 book ai didi

c++ - OpenCV - 带面具的 absdiff

转载 作者:行者123 更新时间:2023-12-02 17:24:36 26 4
gpt4 key购买 nike

我正在尝试使用蒙版计算两个图像的绝对差异,因此在计算差异时只考虑图像的一个区域。但是 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);
当我尝试这个时,我得到一个错误。
错误:

Error: Assertion failed (a_size.width == len) in cv::gemm


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

最佳答案

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

关于c++ - OpenCV - 带面具的 absdiff,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60156131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com