Coder Social home page Coder Social logo

shaunstanislauslau / linux-fake-background-webcam Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fangfufu/linux-fake-background-webcam

0.0 1.0 0.0 65 KB

Faking your webcam background under GNU/Linux.

Dockerfile 24.01% JavaScript 20.65% Shell 13.82% Python 41.51%

linux-fake-background-webcam's Introduction

Linux-Fake-Background-Webcam

Video conferencing software support under Linux is relatively poor. The Linux version of Zoom only supports background replacement via chroma key. The Linux version of Microsoft Team does not support background blur.

Benjamen Elder wrote a blog post, describing a background replacement solution using Python, OpenCV, Tensorflow and Node.js. The scripts in Elder's blogpost do not work out of box. In this repository, I tidy up his scripts, and provide a turn-key solution for creating a virtual webcam with background replacement.

This whole setup has been tested under Debian GNU/Linux, using Thinkpad T440p with an Intel i7-4900MQ CPU.

Prerequisite

Docker

You need to set up Docker. If you want GPU acceleration, you want to set up Nvidia Container Toolkit. There are a lot of guides on the Internet on how to set these up. I am not going to describe them here. Note that if you don't manage to set up Nvidia Container Toolkit, Tensorflow will fall back to CPU. This is in fact how I run mine - my GPU is too old for the current version of Tensorflow.

V4l2loopback

You need to install v4l2loopback. If you are on Debian Buster, you can do the following:

sudo apt install v4l2loopback-dkms

I added module options for v4l2loopback by creating /etc/modprobe.d/v4l2loopback.conf with the following content:

options v4l2loopback devices=1  exclusive_caps=1 video_nr=2 card_label="v4l2loopback"

exclusive_caps is required by some programs, e.g. Zoom and Chrome. video_nr specifies which /dev/video* file is the v4l2loopback device. In this repository, I assume that /dev/video2 is the virtual webcam, and /dev/video0 is the physical webcam.

I also created /etc/modules-load.d/v4l2loopback with the following content:

v4l2loopback

This automatically loads v4l2loopback module at boot, with the specified module options.

How to use this repository

Setting up

  1. Replace fakecam/background.jpg with your own background image.
  2. Build the Docker image by running ./build.sh.
  3. Create the Docker network bridge and containers by running ./create-container.sh.

Using the virtual webcam

  1. Run the containers by running ./run-containers.sh.
  2. Do whatever you need to do, remember that the virtual webcam is at /dev/video2, and your physical webcam should be at /dev/video0. You cannot access the physical webcam when the containers are running.
  3. Stop the containers by running ./stop-containers.sh.

Remove the containers

  1. If you want to remove the containers, run ./remove-containers.sh.
  2. If you want to remove the Docker images, run ./remove-images.sh.

If you want to change the background image

If you want to change your background image, do these steps: 1, 2, 7, 3.

If your bodypix container crashes due to GPU related packages

Please switch to the cpu-only and try again.

Modification to Elder's original post

I removed the hologram_effect() function, because I don't want the hologram effect. I also corrected the command for launching the container instances - the network communication between the container wasn't set up properly. I also replaced his background image to something I took myself.

Afterthoughts

This whole set up is just so amazingly ridiculous - I cannot believe we are running two container instances with network communication, just for a simple webcam background removal. Someone please make a simpler version...

linux-fake-background-webcam's People

Contributors

fangfufu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.