2015-09-10 60 views
0

我正在Motion Detector Script中工作,但是当我运行我的代码时,每当我使用此函数时都会收到此错误,但我不知道为什么它是错误的。我正在使用opencv3,下面是我的代码。我试图运行其他的例子,我从网上获得它到相同的功能,但错误仍然存​​在。任何想法解决它?'BackgroundSubtractorMOG'不是'cv'的成员

这是错误:

cv.cpp: In function ‘int main()’:

cv.cpp:23:4: error: ‘BackgroundSubtractorMOG’ is not a member of ‘cv’

我的代码:

#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <vector> 
#include <iostream> 
#include <sstream> 
#include <opencv2/video/background_segm.hpp> 
using namespace std; 


int main() 
{ 
    //Openthevideofile 
    cv::VideoCapture capture("/home/shar/Desktop/op.mp4"); 
    //checkifvideosuccessfullyopened 
    if (!capture.isOpened()) 
    return 0; 
    //currentvideoframe 
    cv::Mat frame; 
    //foregroundbinaryimage 
    cv::Mat foreground; 
    cv::namedWindow("ExtractedForeground"); 
    //TheMixtureofGaussianobject 
    //used with all default parameters 
    cv::BackgroundSubtractorMOG mog; 

    bool stop(false); 
    //forallframesinvideo 
    while(!stop){ 
    //readnextframeifany 
    if(!capture.read(frame)) 
     break; 
    //updatethebackground 
    //andreturntheforeground 
    mog(frame,foreground,0.01) 
    //learningrate 
    //Complementtheimage 
    cv::threshold(foreground,foreground,128,255,cv::THRESH_BINARY_INV); 
    //showforeground 
    cv::imshow("ExtractedForeground",foreground); 
    //introduceadelay 
    //orpresskeytostop 
    if(cv::waitKey(10)>=0) 
    stop=true; 
    } 


} 
+1

可能重复:http://stackoverflow.com/questions/28213670/cv-has-no-member-backgroundsubtractormog – Tas

回答

1

正如@shar说,答案是this post。为了创建一个智能指针的算法,你需要做的:

cv::Ptr<cv::BackgroundSubtractorMOG2> pMOG2 = cv::createBackgroundSubtractorMOG2(); 

编辑:

而且使用的算法:

float learningRate = 0.01; // or whatever 
cv::Mat foreground; 
pMOG2->apply(frame, foreground, learningRate); 
+0

你需要解决它我应该用这个cv替换你的行:BackgroundSubtractorMOG mog;和mog(帧,前景,0.01)? – shar

+0

我添加了执行该算法的行 – ikaro