0

I am using createBackgroundSubtractorMOG2 which makes a mask of moving object. However, I would like to have a complete segmentation. Currently, only regions around the boundary are white and parts inside are black.

I tried various methods including thresholding but none of them worked. I also looked at cv2.fillPoly but that also did not seem to work.

Here is what I have tried till now

ret, frame = cap.read()
frame = cv2.GaussianBlur(frame,(21,21),0)
fgmask = fbgb.apply(frame)

Any solutions on how can I obtain a proper segmentation of foreground and background.

Image

Here is the screenshot of what I am getting when applied on a video of a dancing girl in a static background

thechargedneutron
  • 802
  • 1
  • 9
  • 24
  • Please clarify or show a picture of what you want for the result. Perhaps you want to get the outer contour and fill that area inside it with white? Perhaps get th outer contour and do fillPoly on that. Some of the area could be filled in via morphology close. – fmw42 Nov 09 '19 at 22:36
  • @fmw42, In the end, I want to separate the foreground into another video with no background part and average the background to get an image of background (with a big hole in between due to occlusion, of course). I tried getting the contours but it is discontinuous and hence, fillPoly on top of that is not making a full foreground mask. – thechargedneutron Nov 09 '19 at 23:54
  • Use morphology to close it up and/or get the convex hull and fill that in. See cv2.convexHull. See https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.html – fmw42 Nov 10 '19 at 00:44

0 Answers0