GithubHelp home page GithubHelp logo

christianlupus / 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 4.9 MB

Faking your webcam background under GNU/Linux.

Dockerfile 7.94% JavaScript 11.18% Shell 0.81% Python 80.06%

linux-fake-background-webcam's Introduction

Linux-Fake-Background-Webcam

Background

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 tidied up his scripts, and provide a turn-key solution for creating a virtual webcam with background replacement and additionally foreground object placement, e.g. a podium.

Rather than using GPU for acceleration as described by the original blog post, this version is CPU-only to avoid all the unnecessary complexities. By downscaling the image sent to bodypix neural network, and upscaling the received mask, this whole setup runs sufficiently fast under Intel i7-4900MQ.

Prerequisite

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.

If you get an error like

OSError: [Errno 22] Invalid argument

when opening the webcam from Python, please install v4l2loopback from the github repo, as you could have an old version from your package manager.

Installing with Docker

Please refer to DOCKER.md. The updated Docker related files were added by liske.

Using Docker is unnecessary. However it makes starting up and shutting down the virtual webcam very easy and convenient. The only downside is that you lose the ability to change background and foreground images on the fly.

Installing without Docker

Please also make sure that your TCP port 127.0.0.1:9000 is free, as we will be using it.

You need to have Node.js. Node.js version 12 is known to work.

You will need Python 3. You need to have pip installed. Please make sure that you have installed the correct version pip, if you have both Python 2 and Python 3 installed. Please make sure that the command pip3 runs.

I am assuming that you have set up your user environment properly, and when you install Python packages, they will be installed locally within your home directory.

You might want to add the following line in your .profile. This line is needed for Debian Buster.

export PATH="$HOME/.local/bin":$PATH

Installation

Run ./install.sh.

Usage

You need to open two terminal windows. In one terminal window, do the following:

cd bodypix
node app.js

In the other terminal window, do the following:

cd fakecam
python3 fake.py

The files that you might want to replace are the followings:

  • fakecam/background.jpg - the background image
  • fakecam/foreground.jpg - the foreground image
  • fakecam/foreground-mask.jpg - the foreground image mask

If you want to change the files above in the middle of streaming, replace them and press CTRL-C

linux-fake-background-webcam's People

Contributors

christianlupus avatar crisidev avatar fangfufu avatar liske avatar rea-jonpad 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.