OpenCV: how to use createBackgroundSubtractorMOG

前端 未结 4 508
太阳男子
太阳男子 2020-12-13 14:44

I was trying to go through this tutorial på OpenCV.org:

http://docs.opencv.org/trunk/doc/tutorials/video/background_subtraction/background_subtraction.html#backgroun

4条回答
  •  孤街浪徒
    2020-12-13 15:32

    I happened to meet this problem today. This tutorial is for opencv 3.0, not for opencv 2.4+, make a few changes as follows:

    //opencv
    #include 
    #include 
    #include 
    //C
    #include 
    //C++
    #include 
    #include 
    
    using namespace cv;
    using namespace std;
    
    //global variables
    Mat frame; //current frame
    Mat fgMaskMOG; //fg mask generated by MOG method
    Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
    Ptr pMOG; //MOG Background subtractor
    Ptr pMOG2; //MOG2 Background subtractor
    int keyboard;
    
    //function declarations
    void help();
    void processVideo(char* videoFilename);
    void processImages(char* firstFrameFilename);
    
    void help()
    {
        cout
            << "--------------------------------------------------------------------------"  << endl
            << "This program shows how to use background subtraction methods provided by "   << endl
            << " OpenCV. You can process both videos (-vid) and images (-img)."              << endl
            << endl
            << "Usage:"                                                                      << endl
            << "./bs {-vid 

提交回复
热议问题