As of writing this, Zoom does not support person/face-detection based virtual background in their Linux-version software. The solution below helps achieve the similar effect, and since it creates a virtual webcam, you can most likely use this solution for any apps that use a webcam, for example, Microsoft Teams. These instructions were originally posted by @BenTheElder, and IMO is a super fun and neat project, especially if you are into computer vision.
What the code is doing essentially is grabbing image frames with Python and OpenCV. For each image, the face/body is cropped using
TensorFlow.js Bodypix, and merged with the specified background. The modified images are then used to create the video feed via
v4l2loopback. I have tested the below instructions with Ubuntu 20.04, code used is archived in https://github.com/pangyuteng/virtual-background
master requires GPU, while branch
cpu-friendly uses only CPU.
EDIT: after getting the below to work, I also found out there is a more refined version by fangfufu https://github.com/fangfufu/Linux-Fake-Background-Webcam which is also based on @BenTheElder's solution.
docker run --gpus all nvidia/cuda:10.0-base nvidia-smi
- install and setup virtual video device as "/dev/video20", and assuming the actual video device is "/dev/video0"
sudo apt-get upgrade -y
sudo apt-get install -y v4l2loopback-dkms v4l2loopback-utils
sudo modprobe -r v4l2loopback
sudo modprobe v4l2loopback devices=1 video_nr=20 card_label="v4l2loopback" exclusive_caps=1
- add root to group video (likely unecessary...)
sudo usermod -aG video root
cat /etc/group | grep video
git clone firstname.lastname@example.org:pangyuteng/virtual-background.git vbkgd
- (for those using CPU) switch branch.
git checkout cpu-friendly
- (optional) adjust camera resolution and fps in
- start the virtual camera via docker-compose (assuming physical video device at
/dev/video0, virtual video device at
/dev/video20 and gpu at
launch zoom/teams/slack..., select
v4l2loopback as webcam
live swap background by replacing file
data/background.jpg - refresh rate hard coded at 3 seconds.