2017-04-26 51 views
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); 

必要利用這種單一的代碼,但我很困惑的地方在上面顯示前面code.the註釋行給我的錯誤聲明BG和BG2。因此,如果任何人都可以提出一個可行的解決方案,那麼這將是一個很大的幫助背景減法器,用於OpenCV的= 3.1.0

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()); 
+0

你可以顯示我得到的錯誤 – eyllanesc

回答

1

必須使用->運營商獲得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

+0

謝謝它的工作。但你能幫我解決因爲你說的改變而導致的錯誤嗎?錯誤類似於 – sophie

+0

/humans/package_bgs/MovingDetection.cpp:610:22:錯誤:'struct cv :: Ptr '沒有名爲'operator()'的成員 bg2.operator()(frame ,前2); – sophie

+0

請[edit](http://stackoverflow.com/posts/43627268/edit)你的答案,並顯示產生錯誤的代碼。 – eyllanesc