背景减法与阴影去除

时间:2016-01-07 15:48:32

标签: c++ opencv background subtraction

我正在使用KTH数据集,其中包含基本人类行为的视频。我尝试使用opencv-2.4.9 BackgroundSubtractorMOG2减去背景,但仍然在结果中获得阴影。

以下是我使用的代码(用C ++编写):

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/background_segm.hpp>
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>

using namespace cv;
using namespace std;

//global variables
Mat frame; //current frame
Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
Ptr<BackgroundSubtractor> pMOG2; //MOG2 Background subtractor
int keyboard;

//function declarations
void processVideo(char* videoFilename);

int main(int argc, char* argv[])
{

    pMOG2 = new BackgroundSubtractorMOG2(); //MOG2 approach
    pMOG2->setInt("nmixtures",3);   
    pMOG2->setDouble("fTau",0.5);

    processVideo("person14_boxing_d1_uncomp.avi");// read the avi file

    //destroy GUI windows
    destroyAllWindows();
    return EXIT_SUCCESS;
}

void processVideo(char* videoFilename) {
    //create the capture object
    VideoCapture capture(videoFilename);
    if(!capture.isOpened()){
        //error in opening the video input
        cerr << "Unable to open video file: " << videoFilename << endl;
        exit(EXIT_FAILURE);
    }


    //read input data. ESC or 'q' for quitting
    while( (char)keyboard != 'q' && (char)keyboard != 27 ){
        //read the current frame
        if(!capture.read(frame)) {
            cerr << "Unable to read next frame." << endl;
            cerr << "Exiting..." << endl;
            //exit(EXIT_FAILURE);
        return;
        }
        pMOG2->operator()(frame, fgMaskMOG2, 0.1
        imshow("FG Mask MOG 2", fgMaskMOG2);
        //get the input from the keyboard
        keyboard = waitKey( 30 );
    }
    //delete capture object
    capture.release();
}

所以请帮我改变代码,这样我才能获得更好的结果。

0 个答案:

没有答案