How can I mask out the non-moving background of my video?
-
I am using the Video In Watcher actor and my video feed is of a room with dancers. I want to isolate the moving parts of the video (the dancers) so that when I layer it over a background on the stage it will be like bluescreen effect with the dancers over the background. It's impractical in my case to have an actual colored background so I was thinking that since its a fixed camera and the dancers are the only thing moving, there should be an actor that picks out just the moving parts and masks out the rest (makes it transparent). Is this possible?
-
@reload2024 said:
isolate the moving parts of the video
There is a method described here by @mark : : webcam-background-removal
Best Wishes
Russell
-
@bonemap That method isn't going to work with me since as the post mentions, if the background moves even a pixel or the lighting changes it will stop working until you can take another empty room capture. Using the difference actor you can get a sort of ghost like set of edges that move with the people, but I'm not sure how to enhance those edges and clean them up to improve it.
-
I don't think you're going to be able to achieve what you want, not just in Isadora but in any 'affordable' system, if the 'difference' method isn't working for you.
Any method for isolating one thing from another relies of a way to do that isolation. Greenscreen is one way, IR masking is another, using a Depth Camera is a third. So if you can't use any of these, how else can you isolate the dancers from the background? -
Frame difference alone will always give you ghosty edges, that's just what it does. What might help is running the difference output through a couple of blurs and a threshold, then smearing or growing the mask a bit so the dancers come out solid instead of outlined. Still won't survive a lighting shift though. Can you lock the camera exposure and white balance and keep the room light constant during the show?
-
Locking exposure and white balance and taking a clean plate under the actual stage lighting are the practical first steps; update that plate if the light changes. For cleanup, run the difference through a small blur and a hard threshold, then dilate/grow the mask so the dancers become solid rather than ghost outlines. A second threshold on a blurred copy can help fill interiors. It will still be motion-only, so anyone standing still will drop out of the matte.
-
Numerous background removal methods can be implemented in Pythoner using Opencv.
Scaling the incoming video to 50% should provide a mask that is clean enough for good real-time usage.
Here's a quick list of possibilities. Some are more useful in very specific cases.
I would look at KNN and/or DNN, specifically DNN if you have a good GPU for AI.Built-in OpenCV options
Method Function Best use MOG2 cv2.createBackgroundSubtractorMOG2()Real-time foreground detection with a stationary camera KNN cv2.createBackgroundSubtractorKNN()Motion-based foreground segmentation GrabCut cv2.grabCut()Extracting objects from still images using an initial region or mask Chroma key cv2.inRange()Green-screen or colour-based background removal DNN cv2.dnn.readNetFromONNX()Running AI-based segmentation models