抽象类类型为"cv :: BackgroundSubtractorMOG2"的对象;不允许.所有的方法都是纯虚拟的 [英] Object of abstract class type "cv::BackgroundSubtractorMOG2" is not allowed. all the methods are pure virtual

查看:794
本文介绍了抽象类类型为"cv :: BackgroundSubtractorMOG2"的对象;不允许.所有的方法都是纯虚拟的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7 64bit的VS2015 + OpenCV3.0中开发代码.这是我想要尝试的演示代码.而且我尝试了很多演示,但遇到了相同的问题:

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:

不允许使用抽象类类型为"cv :: BackgroundSubtractorMOG2"的

对象.所有的方法都是纯虚函数.

object of abstract class type "cv::BackgroundSubtractorMOG2" is not allowed. all the methods are pure virtual function.

演示代码为:

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;
}

我包含很多杂乱的文件,但是我仍然不能使用BackgroundSubtractorMOG2类,更糟糕的是,未声明显示BackgroundSubtractorMOG类.

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.

推荐答案

语法已从OpenCV 2.9.X更改.这将在OpenCV 3.0.0中起作用:

Syntax has changed from OpenCV 2.9.X. This will work in OpenCV 3.0.0:

#include <opencv2\opencv.hpp>

using namespace cv;
using namespace std;
int main() {
    VideoCapture video("1.avi");
    Mat frame, mask, thresholdImage, output;
    int frameNum = 0;

    Ptr<BackgroundSubtractor> pMOG2 = createBackgroundSubtractorMOG2(20, 16, true);
    while (true) {
        video >> frame;
        ++frameNum;
        pMOG2->apply(frame, mask, 0.001);

        cout << frameNum << endl;
        imshow("mask",mask);
        waitKey(10);
    }
    return 0;
}

这篇关于抽象类类型为"cv :: BackgroundSubtractorMOG2"的对象;不允许.所有的方法都是纯虚拟的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆