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

Miscellaneousbgrm
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
Inacap - Programa para pasar las notas de inacap a una hoja de cálculo rápidamente.

Inacap Programa en python para obtener varios datos académicos desde inacap y subirlos directamente a una hoja de cálculo. Cómo funciona Primero que n

Gabriel Barrientos 0 Jul 28, 2022
Tools Elit Adalah Sebuah Script Crack Yang Wajib Tap Yes...

Tools Elit Adalah Sebuah Script Crack Yang Wajib Tap Yes...

Risky [ Zero Tow ] 10 Apr 07, 2022
Integration of CCURE access control system with automation HVAC of a commercial building

API-CCURE-Automation-Quantity-Floor Integration of CCURE access control system with automation HVAC of a commercial building CCURE is an access contro

Alexandre Edson Silva Pereira 1 Nov 24, 2021
Frappe app for authentication, can be used with FrappeVue-AdminLTE

Frappeauth App Frappe app for authentication, can be used with FrappeVue-AdminLTE

Anthony C. Emmanuel 9 Apr 13, 2022
Bring A Trailer(BAT) is a popular online auction website for enthusiast cars. This traverse auction results and saves them as CSV

BaT Data Grabber Bring A Trailer(BAT) is a popular online auction website for enthusiast cars. This traverse auction results and saves them as CSV Bri

Elliot Weil 2 Oct 31, 2021
MIXLAB_NASA_TICKET mixlab 灵感来源于NASA的火星船票

MIXLAB_NASA_TICKET mixlab 灵感来源于NASA的火星船票,我们想要使用开源的代码来定制化这一设计。 其中photo_to_cartoon 是paddle的开源代码:https://github.com/minivision-ai/photo2cartoon-paddle 也借

tongji_cy 38 Feb 20, 2022
Lightweight library for accessing data and configuration

accsr This lightweight library contains utilities for managing, loading, uploading, opening and generally wrangling data and configurations. It was ba

appliedAI Initiative 7 Mar 09, 2022
Analyze FnO trends by using NSE Bhav copy

BhavFnO Analyze FnO trends by using NSE Bhav copy Download entire BhavFnO folder and unzip it In that folder open command window

33 Jan 04, 2023
token vesting escrow with cliff and clawback

Yearn Vesting Escrow A modified version of Curve Vesting Escrow contracts with added functionality: An escrow can have a start_date in the past.

62 Dec 08, 2022
Spyware baseado em Python para Windows que registra como atividades da janela em primeiro plano, entradas do teclado.

Spyware baseado em Python para Windows que registra como atividades da janela em primeiro plano, entradas do teclado. Além disso, é capaz de fazer capturas de tela e executar comandos do shell em seg

Tavares 1 Oct 29, 2021
Pre-1.0 door/chest sound injector for Minecraft

doorjector Pre-1.0 door/chest sound injector for Minecraft. While the game is running, doorjector hotswaps the new sounds for the old right before the

Sam 1 Nov 20, 2021
A module to prevent invites and joins to Matrix rooms by checking the involved server(s)' domain.

Synapse Domain Rule Checker A module to prevent invites and joins to Matrix rooms by checking the involved server(s)' domain. Installation From the vi

matrix.org 4 Oct 24, 2022
Basit bir sunucu - istemci örneği

basitSunucuistemci Aşağıdaki adresteki uygulamadaki process kapanmama sorununun çözülmesi ile oluşturulmuş yeni depo https://github.com/pricheal/pytho

Ali Orhun Akkirman 10 Dec 27, 2022
Exploiting Linksys WRT54G using a vulnerability I found.

Exploiting Linksys WRT54G Exploit # Install the requirements. pip install -r requirements.txt ROUTER_HOST=192.169.1.1 ROUTER_USERNAME=admin ROUTER_P

Elon Gliksberg 31 May 29, 2022
poetry2nix turns Poetry projects into Nix derivations without the need to actually write Nix expressions

poetry2nix poetry2nix turns Poetry projects into Nix derivations without the need to actually write Nix expressions. It does so by parsing pyproject.t

Nix community projects 405 Dec 29, 2022
A lightweight Python module to interact with the Mitre Att&ck Enterprise dataset.

enterpriseattack - Mitre's Enterprise Att&ck A lightweight Python module to interact with the Mitre Att&ck Enterprise dataset. Built to be used in pro

xakepnz 7 Jan 01, 2023
CRC Reverse Engineering Tool in Python

CRC Beagle CRC Beagle is a tool for reverse engineering CRCs. It is designed for commnication protocols where you often have several messages of the s

Colin O'Flynn 51 Jan 05, 2023
Turn crypto miner on/off depending on powerwall charge level

Mining Crypto with Tesla Solar and Powerwalls This script turns a crypto miner on and off when the Tesla Powerwall level drops/rises above a certain t

Matt 1 Nov 09, 2021
Yakuake session management

yman is a python script used for saving/restoring yakuake sessions (currently running commands, working directories, environment variables, tab titles)

Szymon Borecki 6 Jun 25, 2022
Library for managing git hooks

Autohooks Library for managing and writing git hooks in Python. Looking for automatic formatting or linting, e.g., with black and pylint, while creati

Greenbone 165 Dec 16, 2022