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
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
Resources for the 2021 offering of COMP 598

comp598-2021 Resources for the 2021 offering of COMP 598 General submission instructions Important Please read these instructions located in the corre

Derek Ruths 23 May 18, 2022
Print 'text color' and 'text format' on Term with Python

term-printer Print 'text color' and 'text format' on Term with Python ※ It may not work depending on the OS and shell used. PIP $ pip install term-pri

ななといつ 10 Nov 12, 2022
Set up a sidechain for the XRPL quickly and easily

Sidechain Launch Kit Introduction This directory contains python scripts to tests and explore side chains. This document walks through the steps to se

Xpring Engineering 15 Dec 08, 2022
Notes on the Deep Learning book from Ian Goodfellow, Yoshua Bengio and Aaron Courville (2016)

The Deep Learning Book - Goodfellow, I., Bengio, Y., and Courville, A. (2016) This content is part of a series following the chapter 2 on linear algeb

hadrienj 1.7k Jan 07, 2023
Script de monitoramento das teclas do teclado, salvando todos os dados digitados em um arquivo de log juntamente com os dados de rede.

listenerPython Script de monitoramento das teclas do teclado, salvando todos os dados digitados em um arquivo de log juntamente com os dados de rede.

Vinícius Azevedo 4 Nov 27, 2022
Logo DYS (Doküman Yönetim Sitemi) API Python Implementation

dys-connector Logo DYS (Dokuman Yonetim Sistemi) API Python Implementation Python Package: https://pypi.org/project/dys-connector Quick Start from dys

Logo Group 8 Mar 19, 2022
Repository for DNN training, theory to practice, part of the Large Scale Machine Learning class at Mines Paritech

DNN Training, from theory to practice This repository is complementary to the deep learning training lesson given to les Mines ParisTech on the 11th o

Alexandre Défossez 6 Nov 14, 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
Demo code for "Logs in distributed systems" webinar

Hexlet Logs Demo Пререквизиты docker-compose python3 Учетка в DataDog Базовое понимание, что такое логи (можно почитать гайд

Anton Markelov 1 Dec 01, 2021
Glyph Metadata Palette

This plugin for Glyphs3 allows you to associate arbitrary structured metadata to each glyph in your font.

Simon Cozens 4 Jan 26, 2022
Install packages with pip as if you were in the past!

A PyPI time machine Do you wish you could just install packages with pip as if you were at some fixed date in the past? If so, the PyPI time machine i

Thomas Robitaille 51 Jan 09, 2023
The dynamic code loading framework used in LocalStack

localstack-plugin-loader localstack-plugin-loader is the dynamic code loading framework used in LocalStack. Install pip install localstack-plugin-load

LocalStack 5 Oct 09, 2022
This is a working model for which I have used python.

Jarvis_voiceAssistance This is a working model for which I have used python. This model can: 1)Play a video or song on youtube. 2)Tell us time. 3)Tell

Hardik Jain 1 Jan 30, 2022
FindUncommonShares.py is a Python equivalent of PowerView's Invoke-ShareFinder.ps1 allowing to quickly find uncommon shares in vast Windows Domains.

FindUncommonShares The script FindUncommonShares.py is a Python equivalent of PowerView's Invoke-ShareFinder.ps1 allowing to quickly find uncommon sha

Podalirius 184 Jan 03, 2023
RangDev Notepad App With Python

RangDev Notepad-App-With-Python Take down quick and speedy notes! This is a small project of a notepad app built with Tkinter and SQLite3. Database cr

rangga.alrasya 1 Dec 01, 2021
Modeval (or Modular Eval) is a modular and secure string evaluation library that can be used to create custom parsers or interpreters.

modeval Modeval (or Modular Eval) is a modular and secure string evaluation library that can be used to create custom parsers or interpreters. Basic U

2 Jan 01, 2022
A powerful and user-friendly binary analysis platform!

angr angr is a platform-agnostic binary analysis framework. It is brought to you by the Computer Security Lab at UC Santa Barbara, SEFCOM at Arizona S

6.3k Jan 02, 2023
用于红队成员初步快速攻击的全自动化工具。

关于 Author:m0sway Mail:[email protected] Github:https://www.github.com/m0sway/Jud JuD是

m0sway 46 Jul 21, 2022
SuperMario - Python programming class ending assignment SuperMario, using pygame

SuperMario - Python programming class ending assignment SuperMario, using pygame

mars 2 Jan 04, 2022