Sebastian Schmitz
Sebastian Schmitz

Reputation: 1894

getBackgroundImage fails with BackgroundSubtractorMOG

I want to retrieve the BackgroundImage from BackgroundSubtractorMOG with the function getBackgroundImage().

Unfortunately I always get an empty matrix.

Is this behaviour a bug in OpenCV2.4.8 or do I mabye have to do some kind of additional initilization? (If you switch from MOG to MOG2 it works fine.)

Current initialization inspired by this question.

Sample Code:

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

    BackgroundSubtractorMOG mog(3, 4, 0.8);
    cv::VideoCapture cap(0);

    cv::Mat frame, backMOG, foreMOG;
    for(;;){
        cap >> frame;

        mog(frame, foreMOG,-1);
        cv::imshow("foreMOG", foreMOG);

        mog.getBackgroundImage(backMOG);
        if(!backMOG.empty()){
            cv::imshow("backMOG", backMOG); //never reached
        }

        if(cv::waitKey(30) >= 0) break;
    }
    return 0;
}

Upvotes: 1

Views: 2427

Answers (1)

Sebastian Schmitz
Sebastian Schmitz

Reputation: 1894

As @Micka pointed correctly out in the comment: It's just not implemented!

A call of mog.getBackgroundImage(backMOG); jumps to

void BackgroundSubtractor::getBackgroundImage(OutputArray) const {}

in file bgfg_gaussmix2.cpp.

Long story short: BackgroundSubtractorGMG and BackgroundSubtractorMOG don't implement getBackgroundImage currently in OpenCV 2.4.8. Only BackgroundSubtractorMOG2 supports it.

Upvotes: 2

Related Questions