BackgroundRemover is a command line tool to remove background from image and video, made by nadermx to power https://BackgroundRemover.app. If you wonder why it was made read this short blog post.
- python <= 3.6
- python3.6-dev #or what ever version of python you using
- torch and torchvision stable version (https://pytorch.org)
- ffmpeg 4.4+
Go to https://pytorch.org and scroll down to INSTALL PYTORCH
section and follow the instructions.
For example:
PyTorch Build: Stable (1.7.1)
Your OS: Windows
Package: Pip
Language: Python
CUDA: None
To install ffmpeg and python-dev
sudo apt install ffmpeg python3.6-dev
To Install backgroundremover, install it from pypi
pip install --upgrade pip
pip install backgroundremover
Please note that when you first run the program, it will check to see if you have the u2net models, if you do not, it will get them from u2net's google drive, as they say too here, and in this repo the code that pulls it is here
Remove the background from a local file image
backgroundremover -i "/path/to/image.jpeg" -o "output.png"
Sometimes it is possible to achieve better results by turning on alpha matting. Example:
backgroundremover -i "/path/to/image.jpeg" -a -ae 15 -o "output.png"
change the model for diferent background removal methods between u2netp
, u2net
, or u2net_human_seg
backgroundremover -i "/path/to/image.jpeg" -m "u2net_human_seg" -o "output.png"
backgroundremover -i "/path/to/video.mp4" -tv -o "output.mov"
backgroundremover -i "/path/to/video.mp4" -tov "/path/to/videtobeoverlayed.mp4" -o "output.mov"
backgroundremover -i "/path/to/video.mp4" -toi "/path/to/videtobeoverlayed.mp4" -o "output.mov"
backgroundremover -i "/path/to/video.mp4" -tg -o "output.gif"
Make a matte file for premier
backgroundremover -i "/path/to/video.mp4" -mk -o "output.matte.mp4"
Change the framerate of the video (default is set to 30)
backgroundremover -i "/path/to/video.mp4" -fr 30 -tv -o "output.mov"
Set total number of frames of the video (default is set to -1, ie the remove background from full video)
backgroundremover -i "/path/to/video.mp4" -fl 150 -tv -o "output.mov"
Change the gpu batch size of the video (default is set to 1)
backgroundremover -i "/path/to/video.mp4" -gb 4 -tv -o "output.mov"
Change the number of workers working on video (default is set to 1)
backgroundremover -i "/path/to/video.mp4" -wn 4 -tv -o "output.mov"
change the model for diferent background removal methods between u2netp
, u2net
, or u2net_human_seg
and limit the frames to 150
backgroundremover -i "/path/to/video.mp4" -m "u2net_human_seg" -fl 150 -tv -o "output.mov"
- at the moment only a linux 64 Bit docker image is available
- install Docker and Docker-Compose following the official guides
- clone the repo
git clone https://github.com/gtntdev/backgroundremover.git
- cd into the directory
cd backgroundremover
- pull the image
docker-compose pull
(this can take a while) - start the container
docker-compose up -d
- cd into the main media subfolder
cd docker/my_media
- move the file which you wish to edit in this directory, eg
mv ~/test.jpg .
- find out the
name
of your docker containerdocker ps | grep backgroundremover
- convert the file with
docker exec backgroundremover_debian-backgroundremover_1 backgroundremover -i "/my_media/test.jpg" -o "/my_media/test.png"
(where backgroundremover_debian-backgroundremover_1 backgroundremover
is the name
we got from the output above)
- convert logic from video to image to utilize more GPU on image removal
- clean up documentation a bit more
- add ability to adjust and give feedback images or videos to datasets
- add ability to realtime background removal for videos, for streaming
- finish flask server api
- add ability to use other models than u2net, ie your own.
- other
Accepted
Give a link to our project BackgroundRemover.app or this git, telling people that you like it or use it.
bc1q80pshgqgqr7wn3kax59xwvmgq9ftvwla7dew7w
We made it our own package after merging together parts of others, adding in a few features of our own via posting parts as bounty questions on superuser, etc. As well as asked on hackernews earlier to open source the image part, so decided to add in video, and a bit more.
- https://arxiv.org/pdf/2005.09007.pdf
- https://github.com/NathanUA/U-2-Net
- https://github.com/pymatting/pymatting
- https://github.com/danielgatis/rembg
- https://github.com/ecsplendid/rembg-greenscreen
- https://superuser.com/questions/1647590/have-ffmpeg-merge-a-matte-key-file-over-the-normal-video-file-removing-the-backg
- https://superuser.com/questions/1648680/ffmpeg-alphamerge-two-videos-into-a-gif-with-transparent-background/1649339?noredirect=1#comment2522687_1649339
- https://superuser.com/questions/1649817/ffmpeg-overlay-a-video-after-alphamerging-two-others/1649856#1649856
- Copyright (c) 2021-present Johnathan Nader
- Copyright (c) 2020-present Lucas Nestler
- Copyright (c) 2020-present Dr. Tim Scarfe
- Copyright (c) 2020-present Daniel Gatis
Licensed under MIT License