作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这段代码,它基本上对两帧进行“愚蠢”的背景减法。
void FrameDifferenceBGS::operator()(cv::InputArray _image, cv::OutputArray _fgmask, double learningRate)
{
cv::Mat img_input = _image.getMat();
if(img_input.empty())
return;
_fgmask.create(img_input.size(), CV_8U);
cv::Mat img_foreground = _fgmask.getMat();
if(img_input_prev.empty())
{
img_input.copyTo(img_input_prev);
return;
}
cv::absdiff(img_input_prev, img_input, img_foreground);
if(img_foreground.channels() == 3)
cv::cvtColor(img_foreground, img_foreground, CV_BGR2GRAY);
if(enableThreshold)
cv::threshold(img_foreground, img_foreground, threshold, 255, cv::THRESH_BINARY);
if(showOutput)
cv::imshow("Frame Difference", img_foreground);
img_input.copyTo(img_input_prev);
img_foreground.copyTo(_fgmask);
firstTime = false;
}
如果我不在最后添加 img_foreground.copyTo(_fgmask)
,则输出数组不会使用 img_foreground
的结果进行更新,从而导致黑色调用时的图像。
我做错了什么/应该在这里做什么?
最佳答案
我再次检查了您的代码。看起来您正在为 _fgmask 创建新对象。
_fgmask.create(img_input.size(), CV_8U);
我认为这就是您遇到问题的原因。因为论证中的这个引用与这个声明之后的引用不同。为什么不在调用函数之前先调用行。
关于c++ - 不必在 OpenCV 中复制 Mat 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19140052/
我是一名优秀的程序员,十分优秀!