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
This directory gathers the tools developed by the Data Sourcing Working Group

BigScience Data Sourcing Code This directory gathers the tools developed by the Data Sourcing Working Group First Sourcing Sprint: October 2021 The co

BigScience Workshop 27 Nov 04, 2022
A male and female dog names python package

A male and female dog names python package

Fayas Noushad 3 Dec 12, 2021
A dashboard for your code. A build system.

NOTICE: THIS REPO IS NO LONGER UPDATED Changes Changes is a build coordinator and reporting solution written in Python. The project is primarily built

Dropbox 763 Sep 09, 2022
A comprensive software collection for nmea manipulation

nmeatoolkit A comprensive software collection for nmea manipulation; it includes a library and a collections of command line tools. Library pipes: con

Davide Gessa 1 Sep 14, 2022
A simple python script that print the Mandelbrot set for every power of the formal formula.

Python Mandelbrot A simple python script that print the Mandelbrot set for every power of the formal formula.

Paride Giunta 2 Apr 15, 2022
A simple PID tuner and simulator.

PIDtuner-V0.1 PlantPy PID tuner version 0.1 Features Supports first order and ramp process models. Supports Proportional action on PV or error or a sp

3 Jun 23, 2022
Blender addon that enables exporting of xmodels from blender. Great for custom asset creation for cod games

Birdman's XModel Tools For Blender Greetings everyone in the custom cod community. This blender addon should finally enable exporting of custom assets

wast 2 Jul 02, 2022
Structured, dependable legos for Starknet development.

cairomate • Structured, dependable legos for starknet development. Directory Structure contracts ├─ defi │ ├─ ChainlinkPriceOracle — "Simple price or

andreas 127 Nov 23, 2022
Tiling manager which runs on top of EWMH window managers.

PyTyle is an extremely versatile and extensible tiling manager that is meant to be used on top of EWMH window managers. Its feature set was modeled af

55 Jul 29, 2021
Possible solutions to Wordscapes, a mobile game for the android operating system, downloadable from the play store

Possible solutions to Wordscapes, a mobile game for the android operating system, downloadable from the play store

Clifford Onyonka 2 Feb 23, 2022
Automated rop chain generation

This is the accompanying code to the blog post talking about automated rop chain generation. Build the test file with: make Install the dependencies:

Christopher Roberts 14 Nov 22, 2022
Tiny demo site for exploring SameSite=Lax

samesite-lax-demo Background on my blog: Exploring the SameSite cookie attribute for preventing CSRF This repo holds some tools for exploring the impl

Simon Willison 6 Nov 10, 2021
Integration between the awesome window manager and the firefox web browser.

Integration between the awesome window manager and the firefox web browser.

contribuewwt 3 Feb 02, 2022
Minterpy - Multidimensional interpolation in Python.

minterpy is an open-source Python package for a multivariate generalization of the classical Newton and Lagrange interpolation schemes as well as related tasks.

Center for Advanced Systems Understanding 18 Jan 06, 2023
Data Applications Project

DBMS project- Hotel Franchise Data and application project By TEAM Kurukunda Bhargavi Pamulapati Pallavi Greeshma Amaraneni What is this project about

Greeshma 1 Nov 28, 2021
Powerful Assistant

Delta-Assistant Hi I'm Phoenix This project is a smart assistant This is the 1.0 version of this project I am currently working on the third version o

1 Nov 17, 2021
A Regex based linter tool that works for any language and works exclusively with custom linting rules.

renag Documentation Available Here Short for Regex (re) Nag (like "one who complains"). Now also PEGs (Parsing Expression Grammars) compatible with py

Ryan Peach 12 Oct 20, 2022
My solution for a MARL problem on a Grid Environment with Q-tables.

To run the project, run: conda create --name env python=3.7 pip install -r requirements.txt python run.py To-do: Add direction to the state space Take

Merve Noyan 12 Dec 25, 2021
Christmas tree on the desktop.

new-year-tree Christmas tree on the desktop. [Ссылка на статью habr]

Daniil Gorbenko 10 Dec 29, 2022
My solutions to Advent of Code 2021 (written in Python)

Advent of Code 2021 This repository contains my solutions for the 2021 edition of Advent of Code. Please do not expect perfectly polished solutions, m

Nils 2 May 29, 2022