Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Getting background subtraction to work

I am trying to use OpenCV's background subtraction in MSVS 2015. When I try to use it I get very unimpressive results compared to what I see online in examples and videos, and I am wondering what I am doing wrong.

This YouTube video I made demonstrates my problem.

It is hard to explain my problem but essentially I am getting a close to blank mask, and the background subtractor seems to focus on the tiniest of differences rather than massive blobs moving across the scene.

Here is the snippet of code I am using, ignore some unused variables:

void find_hand_bs(hand_detection_type type, std::vector<cv::Point> &digits, cv::Mat &input)
{
    cv::Mat frame = input.clone(); //current frame
    cv::Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
    cv::Ptr<cv::BackgroundSubtractor> pMOG2; //MOG2 Background subtractor
    pMOG2 = cv::createBackgroundSubtractorMOG2(); //MOG2 approach
    pMOG2->apply(frame, fgMaskMOG2);
    imshow("FG Mask MOG 2", fgMaskMOG2);
}

If there is anyone out there with good background subtraction knowledge with OpenCV what is your take on my problem, what settings are going to improve my subtraction? In addition how do I correctly change those settings? Because I have tried to adjust the thresholds and gotten close to no change in the output so I feel I may not be doing it correctly.