Skip to content

Python script to remove background from a video, make use of google MediaPipe

Notifications You must be signed in to change notification settings

nurbxfit/mediapipe_video_bg_removal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

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.

Requirements

  1. FFmpeg
  2. opencv

How to run

  1. cd into this directory
cd py_video_bg_remover
  1. create new virtual environment
python3 -m venv .venv
  1. get into the environment
 .\.venv\Scripts\activate
  1. install dependencies
pip install -r .\requirements.txt
  1. run the script
cd src && python main.py
  1. get out of venv
deactivate

Updates

(23/2/2024) Threadpool

  • 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.

(26/2/2024) Http Server

  • added simple HttpServer to upload video and query processed video
cd src && python main.py

(28/3/2024) Migrate from flask to FastAPI

can view the swagger here

http://0.0.0.0:5001/docs

Example

Input

input image

Output

output image

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.