Simple script demo, on how to remove background from a video. It use google mediapipe segmentation solution, to perform selfie segmentation on the video then it seperate the background from the segmented foreground.
- FFmpeg
- opencv
- cd into this directory
cd py_video_bg_remover
- create new virtual environment
python3 -m venv .venv
- get into the environment
.\.venv\Scripts\activate
- install dependencies
pip install -r .\requirements.txt
- run the script
cd src && python main.py
- get out of venv
deactivate
- I am able to improve the processing time by using threadpool
- only takes 30 seconds when using selfie_segmenter model
- only takes 2.3 minutes when using selfie_multiclass_256x256 model
- able to remove jitter/glitch on output video when using threadpools.
- added simple HttpServer to upload video and query processed video
cd src && python main.py
can view the swagger here
http://0.0.0.0:5001/docs
The output is not perfect because it depends on the mediapipe segmentation model. but you can tune the result using opencv by looking into the file src/utils/workflow.py
.