Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Try this:

cv::Ptr<cv::BackgroundSubtractorMOG2> pMOG2 = cv::createBackgroundSubtractorMOG2();
cv::Mat fgMask;  // Foreground mask

// Update the background model and get the foreground mask
pMOG2->apply(frame, fgMask);

// Blur the foreground mask to reduce the effect of noise and false positives
cv::blur(fgMask, fgMask, cv::Size(15, 15), cv::Point(-1, -1));

// Remove the shadow parts and the noise
cv::threshold(fgMask, fgMask, 128, 255, cv::THRESH_BINARY);