I develop the code in VS2015 + OpenCV3.0 in Windows 7 64bit. This is a demo code that I want have a try. And I have tried many demo but I was coming across the same problem:
object of abstract class type "cv::BackgroundSubtractorMOG2" is not allowed. all the methods are pure virtual function.
The demo code is:
using namespace cv;
using namespace std;
int main() {
VideoCapture video("1.avi");
Mat frame, mask, thresholdImage, output;
//video>>frame;
Ptr<BackgroundSubtractor> pMOG2;
pMOG2 = new BackgroundSubtractorMOG2();
BackgroundSubtractorMOG2 bgSubtractor(20, 16, true);
while (true) {
video >> frame;
++frameNum;
bgSubtractor(frame, mask, 0.001);
cout << frameNum << endl;
//imshow("mask",mask);
//waitKey(10);
}
return 0;
}
I include a lot of heaerd files but I still can not use the class BackgroundSubtractorMOG2
and what is worse, the class of BackgroundSubtractorMOG
is shown undeclared.
Syntax has changed from OpenCV 2.9.X. This will work in OpenCV 3.0.0: