Error: cannot declare variable 'bg of abstract type' cv :: BackgroundSubtractorMOG2 in OpenCV 3

I recently installed OpenCv on my ubuntu 14.10 system and I ran the program, and in fuction cv::BackgroundSubtractorMOG2I got an error.

Error cannot declare variable ‘bg’ to be of abstract type ‘cv::BackgroundSubtractorMOG2’Why I encountered this error

My sample code

int main(int argc, char *argv[]) {
    Mat frame;
    Mat back;
    Mat front;
    vector<pair<Point,double> > hand_middle;
    VideoCapture cap(0);
    BackgroundSubtractorMOG2 bg; //Here I am facing error
    bg.set("nmixtures",3);
    bg.set("detectShadows",false);
    //Rest of my code
    return 0;
}
+4
source share
2 answers

api changed in opencv3.0, you will need to use:

cv::Ptr<BackgroundSubtractorMOG2> bg = createBackgroundSubtractorMOG2(...)
bg->setNMixtures(3);
bg->apply(img,mask);
+5
source

The API in OpenCV 3.0 is now abstract.

cv::Ptr<cv::BackgroundSubtractor> pMOG2;
pMOG2 = cv::createBackgroundSubtractorMOG2();
pMOG2->apply(frame, fgMaskMOG2);

Also sign this link: http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html

+1
source

All Articles