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.

Related tags

Miscellaneous bgrm
Overview

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 :)

How to Use

Take a video camera feed, process it to remove the background, apply a new one, and send it back as a loopback video device.

Buld the kernel module first with make (see dependency notes below!)

Run with sudo ./bgrm.sh

Example:

make ALT_BUILD_DIR=/tmp/bgrm
sudo ./bgrm.sh -b ~/Pictures/Wallpapers/ni-skyline-wallpaper.png -H 720

Note, this will work anywhere WebCams are used.

Dependencies

Packages:

  • make
  • gcc
  • python3.9
  • pip

The application is python based, but uses the v4l2looopback kernel module.

There's a makefile target to download and build that part. However, it must be built in a folder without spaces, so if you want to build it there, provide make a different directory to install to with make ALT_BUILD_DIR=

Comments
  • reporting a few issues I have had on openSuse tumbleweed

    reporting a few issues I have had on openSuse tumbleweed

    Hello!

    I have tried to build and use bgrm on my machine, I was very excited to try it out :-)

    First problem was that I could not build the kernel module and the output was not too helpful. Later on I realized that I haven't had the kernel headers to build the module. On openSuse it should be enough to install the kernel-devel package, but I have installed the kernel-sources package and that installed kernel-devel as dependency. After this the kernel module build was successful, perhaps mention this in the Readme.

    The next problem was when running bgrm.

    ...
    cp: cannot create regular file '.venv/lib/python3.9/site-packages/v4l2.py': No such file or directory
    ...
    

    I verified the path manually and for some reason on my machine the path is with python3.8 not python3.9: .venv/lib/python3.8/site-packages/v4l2.py

    So I edited that path in bgrm.sh and tried again, but this time it complained that opencv-python is not installed:

    $> sudo ./bgrm.sh -b ~/Pictures/Teams/ISS-cupola.webp -H 720
    Traceback (most recent call last):
      File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/home/user/Applications/bgrm/bgrm/__main__.py", line 1, in <module>
        from bgrm import main
      File "/home/user/Applications/bgrm/bgrm/bgrm.py", line 8, in <module>
        pkg_resources.require("opencv-python<=4.4.0.46")
      File "/usr/lib/python3.9/site-packages/pkg_resources/__init__.py", line 886, in require
        needed = self.resolve(parse_requirements(requirements))
      File "/usr/lib/python3.9/site-packages/pkg_resources/__init__.py", line 772, in resolve
        raise DistributionNotFound(req, requirers)
    pkg_resources.DistributionNotFound: The 'opencv-python<=4.4.0.46' distribution was not found and is required by the application
    

    However, when I try to install it manually, it the requirement appears as satisfied:

    sudo /home/user/Applications/bgrm/.venv/bin/python -m pip install opencv-python
    Requirement already satisfied: opencv-python in ./.venv/lib64/python3.8/site-packages (4.4.0.46)
    Requirement already satisfied: numpy>=1.17.3 in ./.venv/lib64/python3.8/site-packages (from opencv-python) (1.21.3)
    

    So now I'm not too sure what to do anymore, any ideas would be helpful!

    And last but not least: thanks a lot for doing this!

    opened by athyla 25
  • Inappropriate ioctl for device error

    Inappropriate ioctl for device error

    Hi, I'm having trouble actually getting this set up. I get this error when I try to run the bgrm script:

    INFO: Created TensorFlow Lite XNNPACK delegate for CPU. Traceback (most recent call last): File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/usr/lib/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/home/Desktop/Misc./Software/bgrm/bgrm/main.py", line 4, in main() File "/home/Desktop/Misc./Software/bgrm/bgrm/bgrm.py", line 28, in main formatVirtualCamera(settings, virtCam, cam) File "/home/Desktop/Misc./Software/bgrm/bgrm/bgrm.py", line 66, in formatVirtualCamera ioctl(virtCam, VIDIOC_S_FMT, format) OSError: [Errno 25] Inappropriate ioctl for device

    A few weeks ago, I was able to get this running after testing out some other solutions, like linux-fake-webcam; however, it would work on zoom, but not teams, which was my target application. Now I'm not getting it to work at all. Any help would be much appreciated.

    opened by zeirew 7
  • OSError:invalid argument on gentoo(again)

    OSError:invalid argument on gentoo(again)

    https://asciinema.org/a/KsoAbIxgRcIwDkfVkNtNBJBIq

    I have patched it and everything something interesting: i changed pip install virtualenv to pip install --user virtualenv because pip without --user breaks python-exec on gentoo

    opened by agent255 5
  • Request: compile using nuitka

    Request: compile using nuitka

    In the past Ive had great success in compiling binaries from python scripts using nuitka. This would be great as it will help to get rid of any python dependencies.

    opened by katakombi 4
  • Mention dependency, TypeError

    Mention dependency, TypeError

    Hi, thanks for making this, it would be very useful to use it in Teams!

    Just wanted to mention that pip is not listed as a dependency, and it is not always included in the python package depending on the distribution; i.e. on Arch there's python and python-pip separately.

    Also, after running make and running the script, I get:

     sudo ./bgrm.sh
    INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
    Format loopback format result (0 good): 0
    Traceback (most recent call last):
      File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/home/fra/bgrm/bgrm/__main__.py", line 4, in <module>
        main()
      File "/home/fra/bgrm/bgrm/bgrm.py", line 47, in main
        frame, noBgFrame = cam.getFrame()
    TypeError: getFrame() missing 1 required positional argument: 'bgImg'
    
    opened by BachoSeven 4
  • Not compatible with python 3.10 (current stable)

    Not compatible with python 3.10 (current stable)

    bgrm

    bgrm.sh: line 15: .venv/bin/activate: No such file or directory bgrm.sh: line 16: python3.9: command not found bgrm.sh: line 20: deactivate: command not found

    packgaged & installed using PKGBUILD from AUR: https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=bgrm-git

    opened by isopix 3
  • On wayland: could not connect to display

    On wayland: could not connect to display

    Hey,

    very nice project!

    I was able to bring it to run on xorg (on another laptop), but not on wayland. I am seeing this error:

    INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
    qt.qpa.xcb: could not connect to display :1.0
    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/path/build/sources/bgrm/.venv/lib/python3.9/site-packages/cv2/qt/plugins" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
    
    Available platform plugins are: xcb.
    

    I tried setting DISPLAY to other values (e.g. WAYLAND_DISPAY). Could these envvars be relevant?

    QT_QPA_PLATFORM=wayland
    QT_WAYLAND_DISABLE_WINDOWDECORATION=1
    

    Is it even supposed to run on wayland?

    opened by zauster 3
  • low fps when using

    low fps when using

    i get ~6 fps with bgrm and 30 without, my specs are : ❯ neofetch

    OS: Gentoo/Linux x86_64 Host: ROG Strix GL10CS 1.0 Kernel: 5.10.61-gentoo-x86_64 Uptime: 58 mins Packages: 1106 (emerge) Shell: zsh 5.8 Resolution: 1920x1080 WM: i3 Theme: Adwaita [GTK2/3] Icons: Adwaita [GTK2/3] Terminal: st Terminal Font: JoyPixels CPU: Intel i7-9700K (8) @ 4.900GHz GPU: NVIDIA GeForce GTX 1660 Ti Memory: 1055MiB / 7880MiB

    opened by agent255 2
  • Error on Fedora 34: OSError: [Errno 25] Inappropriate ioctl for device

    Error on Fedora 34: OSError: [Errno 25] Inappropriate ioctl for device

    Getting an error while running / loading it. Looks like the cam comes online, then it crashes. I did a fresh clone of the repo just to make sure there wouldn't be any odd things with it.

    bgrm on  main took 7s 
    ❯ sudo ./bgrm.sh --blur                     
    INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
    Traceback (most recent call last):
      File "/usr/lib64/python3.9/runpy.py", line 197, in _run_module_as_main
        return _run_code(code, main_globals, None,
      File "/usr/lib64/python3.9/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/home/hugh/git/bgrm/bgrm/__main__.py", line 4, in <module>
        main()
      File "/home/hugh/git/bgrm/bgrm/bgrm.py", line 28, in main
        formatVirtualCamera(settings, virtCam, cam)
      File "/home/hugh/git/bgrm/bgrm/bgrm.py", line 66, in formatVirtualCamera
        ioctl(virtCam, VIDIOC_S_FMT, format)
    OSError: [Errno 25] Inappropriate ioctl for device
    
    opened by hsmalley 1
  • Make script run in user space (might not be distro-agnostic)

    Make script run in user space (might not be distro-agnostic)

    Hi,

    I've committed my changes I've done under Linux Mint to make the process run under user space and install the module permanently.

    You might not be interested in merging this code if it does not generalize to Arch but it might be useful for others.

    Cheers kata

    opened by katakombi 1
  • Implemented video file removal

    Implemented video file removal

    Reason:

    • Now you can pass input/output video files and remove files from them!

    Changes:

    • New VidFile class based on Cam, but using in/out files instead of file
    • Adjust main loop to split into Cam/VirtCam and VidFile paths
    • File Mode settings added to cli args
    opened by blueOkiris 0
Releases(v10)
Owner
Dylan Turner
Maker at heart: music, electronics, video games, software, languages, poetry, and more
Dylan Turner
ABT aka Animated Background Tool is a windows only python program that makes it that you can have animated background.

ABT ABT aka Animated Background Tool is a windows only python program that makes it that you can have animated background. ???????? ????, An Important

Yeeterboi4 2 Jul 16, 2022
- Auto join teams teams ( from calendar invite )

Auto Join Teams Meetings Requirements: Python 3.7 or higher Latest Google Chrome This script automatically logins to your account and joins the meetin

Prajin Khadka 10 Aug 20, 2022
Wunderland desktop wallpaper and Microsoft Teams background.

Wunderland Professional Impress your colleagues, friends and family with this edition of the "Wunderland" wallpaper. With the nostalgic feel of the or

null 3 Dec 14, 2022
A tool to replace all osu beatmap backgrounds at once.

OsuBgTool A tool to replace all osu beatmap backgrounds at once. Requirements You need to have python 3.6 or newer installed. That's it. How to Use Ju

Aditya Gupta 1 Oct 24, 2021
A Linux webcam plugin for BGMv2 as used in our demos.

The goal of this repository is to supplement the main Real-Time High Resolution Background Matting repo with a working demo of a videoconferencing plu

Andrey Ryabtsev 144 Dec 27, 2022
LSO, also known as Linux Swap Operator, is a software with both GUI and terminal versions that you can manage the Swap area for Linux operating systems.

LSO - Linux Swap Operator Türkçe - LSO Nedir? LSO, diğer adıyla Linux Swap Operator Linux işletim sistemleri için Swap alanını yönetebileceğiniz hem G

Eren İnce 4 Feb 9, 2022
BloodCheck enables Red and Blue Teams to manage multiple Neo4j databases and run Cypher queries against a BloodHound dataset.

BloodCheck BloodCheck enables Red and Blue Teams to manage multiple Neo4j databases and run Cypher queries against a BloodHound dataset. Installation

Mr B0b 16 Nov 5, 2021
List of Linux Tools I put on almost every linux / Debian host

Linux-Tools List of Linux Tools I put on almost every Linux / Debian host Installed: geany --> GUI editor/ notepad++ like chkservice --> TUI Linux ser

Stew Alexander 20 Jan 2, 2023
Organize seu linux - organize your linux

OrganizeLinux Organize seu linux - organize your linux Organize seu linux Uma forma rápida de separar arquivos dispersos em pastas. formatos a serem c

Marcus Vinícius Ribeiro Andrade 1 Nov 30, 2021
Track testrail productivity in automated reporting to multiple teams

django_web_app_for_testrail testrail is a test case management tool which helps any organization to track all consumption and testing of manual and au

Vignesh 2 Nov 21, 2021
Open-source data observability for modern data teams

Use cases Monitor your data warehouse in minutes: Data anomalies monitoring as dbt tests Data lineage made simple, reliable, and automated dbt operati

null 889 Jan 1, 2023
Feature engineering library that helps you keep track of feature dependencies, documentation and schema

Feature engineering library that helps you keep track of feature dependencies, documentation and schema

null 28 May 31, 2022
A simple script written using symbolic python that takes as input a desired metric and automatically calculates and outputs the Christoffel Pseudo-Tensor, Riemann Curvature Tensor, Ricci Tensor, Scalar Curvature and the Kretschmann Scalar

A simple script written using symbolic python that takes as input a desired metric and automatically calculates and outputs the Christoffel Pseudo-Tensor, Riemann Curvature Tensor, Ricci Tensor, Scalar Curvature and the Kretschmann Scalar

null 2 Nov 27, 2021
A Linux program to create a Windows USB stick installer from a real Windows DVD or image.

WoeUSB-ng A Linux program to create a Windows USB stick installer from a real Windows DVD or image. This package contains two programs: woeusb: A comm

Longinus 1 Nov 19, 2021
A python package to manage the stored receiver-side Strain Green's Tensor (SGT) database of 3D background models and able to generate Green's function and synthetic waveform

A python package to manage the stored receiver-side Strain Green's Tensor (SGT) database of 3D background models and able to generate Green's function and synthetic waveform

Liang Ding 7 Dec 14, 2022
This is the core of the program which takes 5k SYMBOLS and looks back N years to pull in the daily OHLC data of those symbols and saves them to disc.

This is the core of the program which takes 5k SYMBOLS and looks back N years to pull in the daily OHLC data of those symbols and saves them to disc.

Daniel Caine 1 Jan 31, 2022
A python script that changes your desktop background based on current weather and time of the day.

Desktop background wallpaper, based on current weather and time A python script that changes your computer's desktop background based on current weath

Maj Gaberšček 1 Nov 16, 2021
A program that takes Python classes and turns them into CSS classes.

PyCSS What is it? PyCSS is a micro-framework to speed up the process of writing bulk CSS classes. How does it do it? With Python!!! First download the

T.R Batt 0 Aug 3, 2021