Skip to content

Instantly share code, notes, and snippets.

@sxiii
Last active June 18, 2021 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sxiii/384c332ac9d7bf4b5598781815aa5348 to your computer and use it in GitHub Desktop.
Save sxiii/384c332ac9d7bf4b5598781815aa5348 to your computer and use it in GitHub Desktop.
Replace webcam background on Fedora Linux 32

How to replace webcam background with neural network processing on Linux

Starting requirements: Linux, Bash, Fedora

sudo dnf install wget git # Only if you don't have them already

We need RPM Fusion repos here for v4l2loopback

wget http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-32.noarch.rpm
sudo dnf install ./rpmfusion*rpm
sudo dnf update
sudo dnf install python3.6 ffmpeg v4l2loopback
git clone https://gitlab.com/parrot_parrot/ms-teams-replace-background
cd ms-teams*
curl https://bootstrap.pypa.io/get-pip.py | sudo -H python3.6 # We also need pip3.6
pip3.6 install numpy matplotlib scipy scikit-image # ... and these packages

Now, open the file requirements.txt and remove ALL versions in there:

scikit_image
pyfakewebcam
opencv_python
imutils
tensorflow_gpu
numpy
scikit-image
tensorflow

Finally, we can install requirements

pip3.6 install -r requirements.txt

Now we need to gather additional info

ls /dev/video* # Check out your video devices - your camera probably will be /dev/video0
ffplay /dev/video0 # Let's check that it's correct camera (if not - check the others, /dev/video1 etc.)

In the output of ffplay command you will be also able to see width and height of your video (for example 640x480). Remember those numbers as you will need them as an input parameter to a script.

Create new camera

sudo modprobe v4l2loopback devices=1

Run the script and set the parameters

--width (default=640): The width of you webcam footage
--height (default=480): The height of you webcam footage
--image (default='office.jpeg'): The path to background image
--input-stream (default=0): The number of the video device, where webcam is recorded.
--output-stream (default=2): The number of the video device, where the modified video is streamed.

Example:

python3.6 run.py --width 1280 --height 720 --input-stream 1 --output-stream 2

Other useful info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment