https://github.com/blueokiris/bgrm
Virtual webcam that takes real webcam footage and replaces the background in order to have Virtual Backgrounds in MS Teams for Linux where the feature is unimplemented.
https://github.com/blueokiris/bgrm
background-removal linux python v4l2loopback video
Last synced: about 20 hours ago
JSON representation
Virtual webcam that takes real webcam footage and replaces the background in order to have Virtual Backgrounds in MS Teams for Linux where the feature is unimplemented.
- Host: GitHub
- URL: https://github.com/blueokiris/bgrm
- Owner: blueOkiris
- License: gpl-3.0
- Created: 2021-10-22T05:53:26.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-16T09:35:55.000Z (over 2 years ago)
- Last Synced: 2024-11-10T02:29:09.584Z (11 months ago)
- Topics: background-removal, linux, python, v4l2loopback, video
- Language: Python
- Homepage:
- Size: 3.56 MB
- Stars: 83
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Background Remover
## The Need
It's been good long while since Microsoft first released a Teams version for Linux and yet, one of Teams' coolest features doesn't exist in said Linux version: removable backgrounds. As someone who uses Linux for their daily driver, this annoys me.
Well, I'm an engineer, so of course, I found a solution.
Using OpenCV and a v4l2loopback device (basically a virtual webcam you can write data to), I threw together a Python application that takes your normal webcam input, removes and replaces the background, and outputs that to the created video device. Problem solved :)
Note, this will work anywhere WebCams are used, not just Teams
Now, the program can also be used to remove backgrounds from video files and save them as video files as well!
## How to Use
### WebCam Replacement
Dependencies:
- x86 or x64 only as mediapipe, a dependency, doesn't support ARM
+ Although, there are versions of mediapipe that may work if you have Apple Silicon or a Raspberry Pi
+ If on ARM, you'll have to install from the GitHub source and modify pyproject.toml to use a custom mediapipe library like [mediapipe-silicon](https://pypi.org/project/mediapipe-silicon/) or [mediapipe-rpi4](https://pypi.org/project/mediapipe-rpi4/) or something else
- python >= 3.8 (3.11 is what's supported officially)
- pip
- v4l2loopbackSetup:
1. Configure v4l2loopback (may not be necessary):
- Recommended something like this:
```
export DEVICE_ARR=(`ls /sys/devices/virtual/video4linux | tr -d 'video'`); \
sudo modprobe v4l2loopback \
devices=1 exclusive_caps=1 video_nr=${DEVICE_ARR[1]} max_buffers=2 \
card_label=v4l2lo
```
2. Install with `pip install bgrm`Then, you can run:
- Run with `python -m bgrm ` (use `--help` to see all options)
- Example: `python -m bgrm -b ~/Pictures/Wallpapers/ni-skyline-wallpaper.png -w 320 -H 240 -s 2.0`### File Replacement
You can also remove the background from video files. It works just like the WebCam, but instead of setting the `--camera` cli arg, you call the program like this:
`python -m bgrm --file_mode -i -o `
## Build from Repo
You can also build the package yourself from source (or grab the latest version from the releases tab)
To do that you need the "poetry" build system.
Run `poetry build` and install the whl from the dist/ folder