# 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
- v4l2loopback
Setup:
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 <options>` (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 <input file> -o <output file> <other options>`
## 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
Raw data
{
"_id": null,
"home_page": "https://github.com/blueOkiris/bgrm",
"name": "bgrm",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "bgrm,background,removal,teams,linux,mediapipe,opencv,bg,rm",
"author": "Dylan Turner",
"author_email": "dylan.turner@tutanota.com",
"download_url": "",
"platform": null,
"description": "# Background Remover\n\n## The Need\n\nIt'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.\n\nWell, I'm an engineer, so of course, I found a solution.\n\nUsing 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 :)\n\nNote, this will work anywhere WebCams are used, not just Teams\n\nNow, the program can also be used to remove backgrounds from video files and save them as video files as well!\n\n## How to Use\n\n### WebCam Replacement\n\nDependencies:\n - x86 or x64 only as mediapipe, a dependency, doesn't support ARM\n + Although, there are versions of mediapipe that may work if you have Apple Silicon or a Raspberry Pi\n + 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\n - python >= 3.8 (3.11 is what's supported officially)\n - pip\n - v4l2loopback\n\nSetup:\n1. Configure v4l2loopback (may not be necessary):\n - Recommended something like this:\n ```\n export DEVICE_ARR=(`ls /sys/devices/virtual/video4linux | tr -d 'video'`); \\\n sudo modprobe v4l2loopback \\\n devices=1 exclusive_caps=1 video_nr=${DEVICE_ARR[1]} max_buffers=2 \\\n card_label=v4l2lo\n ```\n2. Install with `pip install bgrm`\n\nThen, you can run: \n- Run with `python -m bgrm <options>` (use `--help` to see all options)\n- Example: `python -m bgrm -b ~/Pictures/Wallpapers/ni-skyline-wallpaper.png -w 320 -H 240 -s 2.0`\n\n### File Replacement\n\nYou 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:\n\n`python -m bgrm --file_mode -i <input file> -o <output file> <other options>`\n\n## Build from Repo\n\nYou can also build the package yourself from source (or grab the latest version from the releases tab)\n\nTo do that you need the \"poetry\" build system.\n\nRun `poetry build` and install the whl from the dist/ folder\n\n",
"bugtrack_url": null,
"license": "GPL-3.0-only",
"summary": "Remove backgrounds from video feeds in your web cam applications.",
"version": "11",
"project_urls": {
"Homepage": "https://github.com/blueOkiris/bgrm",
"Repository": "https://github.com/blueOkiris/bgrm"
},
"split_keywords": [
"bgrm",
"background",
"removal",
"teams",
"linux",
"mediapipe",
"opencv",
"bg",
"rm"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b80d21a22426c66cd251ff5fa8a05483e17ffb150532787dd5945b59c17d6761",
"md5": "77f1846ba1144da6d10a8def343e7557",
"sha256": "87627a4ab6bfdff3dcf451b4690fe10430e61f712092946a32d05fb5887b6495"
},
"downloads": -1,
"filename": "bgrm-11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "77f1846ba1144da6d10a8def343e7557",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 19512,
"upload_time": "2023-05-16T09:34:23",
"upload_time_iso_8601": "2023-05-16T09:34:23.686880Z",
"url": "https://files.pythonhosted.org/packages/b8/0d/21a22426c66cd251ff5fa8a05483e17ffb150532787dd5945b59c17d6761/bgrm-11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-16 09:34:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "blueOkiris",
"github_project": "bgrm",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "bgrm"
}