# BackgroundRemover
![Background Remover](https://raw.githubusercontent.com/nadermx/backgroundremover/main/examplefiles/backgroundremoverexample.png)
<img alt="background remover video" src="https://raw.githubusercontent.com/nadermx/backgroundremover/main/examplefiles/backgroundremoverprocessed.gif" height="200" /><br>
BackgroundRemover is a command line tool to remove background from [image](https://github.com/nadermx/backgroundremover#image) and [video](https://github.com/nadermx/backgroundremover#video) using AI, made by [nadermx](https://john.nader.mx) to power [https://BackgroundRemoverAI.com](https://backgroundremoverai.com). If you wonder why it was made read this [short blog post](https://johnathannader.com/my-first-open-source-project/).<br>
### Requirements
* python >= 3.6
* python3.6-dev #or what ever version of python you use
* torch and torchvision stable version (https://pytorch.org)
* ffmpeg 4.4+
* To clarify, you must install both python and whatever dev version of python you installed. IE; python3.10-dev with python3.10 or python3.8-dev with python3.8
#### How to install torch and fmpeg
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
```
### Installation
To Install backgroundremover, install it from pypi
```bash
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 pull them from this repo
It is also possible to run this without installing it via pip, just clone the git to local start a virtual env and install requirements and run
```bash
python -m backgroundremover.cmd.cli -i "video.mp4" -mk -o "output.mov"
```
and for windows
```bash
python.exe -m backgroundremover.cmd.cli -i "video.mp4" -mk -o "output.mov"
```
### Installation using Docker
```bash
git clone https://github.com/nadermx/backgroundremover.git
cd backgroundremover
docker build -t bgremover .
alias backgroundremover='docker run -it --rm -v "$(pwd):/tmp" bgremover:latest'
```
### Usage as a cli
## Image
Remove the background from a local file image
```bash
backgroundremover -i "/path/to/image.jpeg" -o "output.png"
```
### Advance usage for image background removal
Sometimes it is possible to achieve better results by turning on alpha matting. Example:
```bash
backgroundremover -i "/path/to/image.jpeg" -a -ae 15 -o "output.png"
```
change the model for different background removal methods between `u2netp`, `u2net`, or `u2net_human_seg`
```bash
backgroundremover -i "/path/to/image.jpeg" -m "u2net_human_seg" -o "output.png"
```
## Video
### remove background from video and make transparent mov
```bash
backgroundremover -i "/path/to/video.mp4" -tv -o "output.mov"
```
### remove background from local video and overlay it over other video
```bash
backgroundremover -i "/path/to/video.mp4" -tov "/path/to/videtobeoverlayed.mp4" -o "output.mov"
```
### remove background from local video and overlay it over an image
```bash
backgroundremover -i "/path/to/video.mp4" -toi "/path/to/videtobeoverlayed.mp4" -o "output.mov"
```
### remove background from video and make transparent gif
```bash
backgroundremover -i "/path/to/video.mp4" -tg -o "output.gif"
```
### Make matte key file (green screen overlay)
Make a matte file for premiere
```bash
backgroundremover -i "/path/to/video.mp4" -mk -o "output.matte.mp4"
```
### Advance usage for video
Change the framerate of the video (default is set to 30)
```bash
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)
```bash
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)
```bash
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)
```bash
backgroundremover -i "/path/to/video.mp4" -wn 4 -tv -o "output.mov"
```
change the model for different background removal methods between `u2netp`, `u2net`, or `u2net_human_seg` and limit the frames to 150
```bash
backgroundremover -i "/path/to/video.mp4" -m "u2net_human_seg" -fl 150 -tv -o "output.mov"
```
## Todo
- 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
### Pull requests
Accepted
### If you like this library
Give a link to our project [BackgroundRemoverAI.com](https://backgroundremoverai.com) or this git, telling people that you like it or use it.
### Reason for project
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.
### References
- 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
### License
- Copyright (c) 2021-present [Johnathan Nader](https://github.com/nadermx)
- Copyright (c) 2020-present [Lucas Nestler](https://github.com/ClashLuke)
- Copyright (c) 2020-present [Dr. Tim Scarfe](https://github.com/ecsplendid)
- Copyright (c) 2020-present [Daniel Gatis](https://github.com/danielgatis)
Code Licensed under [MIT License](./LICENSE.txt)
Models Licensed under [Apache License 2.0](./models/license)
没有合适的资源?快使用搜索试试~ 我知道了~
背景移除工具:一个方便实用的图像和视频背景移除工具,可以帮助用户轻松地将图像和视频中的背景去除,从而实现更好的视觉效果
共47个文件
py:11个
whl:5个
gz:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 58 浏览量
2023-11-24
14:56:53
上传
评论
收藏 325.99MB ZIP 举报
温馨提示
一个方便实用的图像和视频背景移除工具,可以帮助用户轻松地将图像和视频中的背景去除,从而实现更好的视觉效果。
资源推荐
资源详情
资源评论
收起资源包目录
backgroundremover-main.zip (47个子文件)
backgroundremover-main
.editorconfig 176B
setup.py 1KB
.github
workflows
docker-image-build.yml 1KB
FUNDING.yml 65B
LICENSE.txt 1KB
backgroundremover
__init__.py 175B
u2net
__init__.py 0B
u2net.py 15KB
data_loader.py 11KB
detect.py 4KB
utilities.py 12KB
cmd
__init__.py 0B
server.py 3KB
cli.py 8KB
bg.py 7KB
olddist
backgroundremover-0.2.3.tar.gz 18KB
backgroundremover-0.2.1-py2.py3-none-any.whl 18KB
backgroundremover-0.2.1.tar.gz 18KB
backgroundremover-0.2.2.tar.gz 18KB
backgroundremover-0.2.4.tar.gz 18KB
backgroundremover-0.2.3-py2.py3-none-any.whl 18KB
backgroundremover-0.2.2-py2.py3-none-any.whl 18KB
backgroundremover-0.2.4-py2.py3-none-any.whl 18KB
dist
backgroundremover-0.2.5.tar.gz 18KB
backgroundremover-0.2.5-py2.py3-none-any.whl 18KB
Dockerfile 572B
pyproject.toml 230B
requirements.txt 350B
models
u2hab 50MB
u2ab 50MB
u2ad 18.12MB
license 11KB
u2aa 50MB
u2netp.pth 4.47MB
u2hac 50MB
u2ac 50MB
u2haa 50MB
u2had 18.15MB
MANIFEST.in 183B
.gitignore 3KB
setup.cfg 198B
examplefiles
backgroundremoverprocessed.gif 8.2MB
backgroundremoverexample2.png 202KB
backgroundremoverexample.png 442KB
README.md 387B
.dockerignore 42B
README.md 6KB
共 47 条
- 1
资源评论
UnknownToKnown
- 粉丝: 1w+
- 资源: 561
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功