I can answer in C++ using the BackgroundSubtractorMOG2:
You can either use erosion or pass a higher threshold value to the MOG background subtractor to remove the noise. In order to completely get rid of the noise and false positives, you can also blur the mask image and then apply a threshold:
// Blur the mask image
blur(fgMaskMOG2, fgMaskMOG2, Size(5,5), Point(-1,-1));
// Remove the shadow parts and the noise
threshold(fgMaskMOG2, fgMaskMOG2, 128, 255, 0);
Now you can easily find the rectangle bounding the foreground region and pass this area to the cascade classifier:
// Find the foreground bounding rectangle
Mat fgPoints;
findNonZero(fgMaskMOG2, fgPoints);
Rect fgBoundRect = boundingRect(fgPoints);
// Crop the foreground ROI
Mat fgROI = image(fgBoundRect);
// Detect the faces
vector<Rect> faces;
face_cascade.detectMultiScale(fgROI, faces, 1.3, 3, 0|CV_HAAR_SCALE_IMAGE, Size(32, 32));
// Display the face ROIs
for(size_t i = 0; i < faces.size(); ++i)
{
Point center(fgBoundRect.x + faces[i].x + faces[i].width*0.5, fgBoundRect.y + faces[i].y + faces[i].height*0.5);
circle(image, center, faces[i].width*0.5, Scalar(255, 255, 0), 4, 8, 0);
}
In this way, you will reduce the search area for the cascade classifier, which not only makes it faster but also reduces the false positive faces.