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
✔️ Create to-do lists to easily manage your ideas and work.

Todo List + Add task + Remove task + List completed task + List not completed task + Set clock task time + View task statistics by date Changelog v 1.

Abbas Ataei 30 Nov 28, 2022
Simple Crud Python vs MySQL

Simple Crud Python vs MySQL The idea came when I was studying MySQ... A desire to create a python program that can give access to a "localhost" databa

Lucas 1 Jan 21, 2022
Syntax highlighting for yarn.lock and bun.lockb files

Yarn.lock Syntax Highlighting Syntax highlighting for yarn.lock and bun.lockb files Installation Plugin is not publushed yet on Package Control, to in

Alexander Kuznetsov 4 Jul 06, 2022
Mmr image postbot - Бот для создания изображений с новыми релизами в сообщество ВК MMR Aggregator

Mmr image postbot - Бот для создания изображений с новыми релизами в сообщество ВК MMR Aggregator

Max 3 Jan 07, 2022
Just RESTing

petnica-api-workshop Just RESTing Setup Using pipenv You can setup this project with pipenv if you want isolated libraries. After you've installed pip

Aleksa Tešić 1 Oct 23, 2021
Credit Card Fraud Detection

Credit Card Fraud Detection For this project, I used the datasets from the kaggle competition called IEEE-CIS Fraud Detection. The competition aims to

RayWu 4 Jun 21, 2022
A simple weather app.

keather A simple weather app. This is currently not finished. Dependencies: yay -S python-beautifulsoup4 tk

1 Jan 09, 2022
The most hackable keyboard in all the land

MiRage Modular Keyboard © 2021 Zack Freedman of Voidstar Lab Licensed Creative Commons 4.0 Attribution Noncommercial Share-Alike The MiRage is a 60% o

Zack Freedman 558 Dec 30, 2022
Repositório contendo atividades no curso de desenvolvimento de sistemas no SENAI

SENAI-DES Este é um repositório contendo as atividades relacionadas ao curso de desenvolvimento de sistemas no SENAI. Se é a primeira vez em contato c

Abe Hidek 4 Dec 06, 2022
Add any Program in any language you like or add a hello world Program ❣️ if you like give us :star:

Welcome to the Hacktoberfest 2018 Hello-world 📋 This Project aims to help you to get started with using Github. You can find a tutorial here What is

Aniket Sharma 1.5k Nov 16, 2022
Semester Project on Signal Processing @CS UCU 2021

Blur Detection with Haar Wavelet Transform Requirements Python3 opencv-python PyWavelets Install these using the following command: $ pip install -r r

ButynetsD 2 Oct 15, 2022
Fonts used to be an install-and-forget thing, but many of are now updated regularly.

Your font manager. Fonts used to be an install-and-forget thing, but many of are now updated regularly. fontman helps you keep track of the fonts you

Nico Schlömer 20 Feb 07, 2022
Compile Binary Ninja's HLIL IR to LLVM, for purposes of compiling it back to a binary again.

Compiles BinaryNinja's HLIL to LLVM Approach Sweep binary for global variables, create them Sweep binary for (used?) external functions, declare those

Kyle Martin 31 Nov 10, 2022
1. 네이버 카페 댓글을 빨리 다는 기능

naver_autoprogram 기능 설명 네이버 카페 댓글을 빨리 다는 기능 네이버 카페 자동 출석 체크 기능 동작 방식 카페 댓글 기능 기본 동작은 주기적인 스케쥴 동작으로 해당 카페 ID 와 특정 API 주소로 대상이 새글을 작성했는지 체크. 해당 대상이 새글 등

1 Dec 22, 2021
Free components that wrap up Python into Delphi and Lazarus (FPC)

Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi and Lazarus (FPC). They let you easily execute Python scri

747 Jan 02, 2023
Write complicated anonymous functions other than lambdas in Python.

lambdex allows you to write multi-line anonymous function expression (called a lambdex) in an idiomatic manner.

Xie Jingyi 71 May 19, 2022
Automatically deletes Capital One Eno virtual cards for when you've made a couple too many.

eno-delete Automatically deletes Capital One Eno virtual cards for when you've made a couple too many. Warning: Program will delete ALL virtual cards

h3x 3 Sep 29, 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 05, 2021
Python Multilingual Ucrel Semantic Analysis System

PymUSAS Python Multilingual Ucrel Semantic Analysis System, it currently is a rule based token level semantic tagger which can be added to any spaCy p

UCREL 13 Nov 18, 2022
Simple Assembler with python

Assembler with python converts assembly source code to machine code Requirements Python 3 🐍 Usage python main.py [source] [output] [source] : Path t

Amir mohammad 1 Dec 24, 2021