opencv=3.1.0 的背景减法器

background subtractor for opencv=3.1.0

//cv::BackgroundSubtractorMOG2 bg = cv::BackgroundSubtractorMOG2();
cv::Ptr< BackgroundSubtractorMOG2 >createBackgroundSubtractorMOG2();
bg.set("history", 1000);
bg.set("nmixtures", 3);
bg.set("backgroundRatio", 0.7);
bg.set("detectShadows", false);

//background subtractor for the filterTotalBackground results
//cv::BackgroundSubtractorMOG2 bg2 = cv::BackgroundSubtractorMOG2();
Ptr< BackgroundSubtractorMOG2  >createBackgroundSubtractorMOG2 ();
bg2.set("history", 1000);
bg2.set("nmixtures", 3);
bg2.set("backgroundRatio", 0.7);
bg2.set("detectShadows", false);

需要在单个代码中使用它,但我不清楚在上面显示的何处声明 bg 和 bg2 code.the 如果有人可以建议,前面的评论行给了我 errors.so一个可行的解决方案,那将是一个很大的帮助

bg->operator()(total, fore); //error is here

//Computes a background image.
//C++: void BackgroundSubtractor::getBackgroundImage(OutputArray backgroundImage) const¶
bg->getBackgroundImage(back);


//find the moving objects in the frame and cv::erode the image
bg2->operator()(frame, fore2);    //error is here
bg2->getBackgroundImage(back2);
cv::erode(fore2, fore2, cv::Mat());

您必须使用 -> 运算符来获取 cv::BackgroundSubtractorMOG2 对象。

cv::Ptr<cv::BackgroundSubtractorMOG2> bg = cv::createBackgroundSubtractorMOG2();
bg->setHistory(1000);
bg->setNMixtures(3);
bg->setBackgroundRatio(0.7);
bg->setDetectShadows(false);

另一个错误:

您必须更改:

bg->operator()(frame, fore);

bg->apply(frame, fore);

我看到您使用的是旧教程,您可以使用这个 tutorial

实际上,我在 ofxCvMOG2.cpp,

中改变了它的工作方式
mog2 = new cv::BackgroundSubtractorMOG2();

作者:

mog2 = cv::createBackgroundSubtractorMOG2(500,16,true);

也就是说,在开头设置历史、阈值和检测阴影,并注释:

mog2->set("nmixtures", nMixtures);
mog2->set("detectShadows",1);