:linux:
:movie-camera:April 9th, 2020
With many of us around the globe under shelter in place due to COVID-19video calls have become a lot more common. In particular, ZOOM hascontroversially become very popular. Arguably Zoom’s most interesting featureis the “Virtual Background” support which allows users to replacethe background behind them in their webcam video feed with any image (or video).
I’ve been using Zoom for a long time at work for Kubernetes open source meetings,usually from my company laptop. With daily “work from home” I’m now inclined touse my more powerful and ergonomic personal desktop for some of my open source work.
I'm on videoconferencing software a big part of my days now that I work from home and would love to be able to blur just the background. Is there a virtual cam software that could blur my background in real time? /edit I use Google Meet and it doesn't have a built in background blur setting like Zoom or Skype. Download this app from Microsoft Store for Windows 10, Windows 8.1, Windows 10 Mobile, Windows Phone 8.1, Windows 10 Team (Surface Hub), HoloLens. See screenshots, read the latest customer reviews, and compare ratings for Blur Photo Background Maker. Re: Blur Background on Mac OS. Press the CTRL+Shift+P combination. If things go blurry, during your video call, you know that your PC has this feature. The second option is to start your video from a meeting. Then, click on the Ellipsis icon from the meeting options and choose Blur My Background. Apr 01 2020 07:34 AM.
Unfortunately, Zoom’s linux client only supports the “chroma-key” A.K.A. “green screen”background removal method. This method requires a solid color backdrop, ideallya green screen with uniform lighting.
- Live Streamer CAM 313. The Live Streamer CAM 313 (PW313) is a plug and play USB webcam that records in 1080p30 for podcasting, streaming, and gaming. PW313 comes with 2 built-in microphones (mono).
- This is a Windows-based desktop application that can work in tandem with a regular webcam. It can be paired up with the likes of Skype, Webex, Zoom, Google Hangouts and more besides and allows you.
Since I do not have a green screen I decided to simply implement my own backgroundremoval, which was obviously better than cleaning my apartment or just usingmy laptop all the time. :grin:
It turns out we can actually get pretty decent results with off the shelf, open sourcecomponents and just a little of our own code.
# Reading The Camera
First thing’s first: How are we going to get the video feed from our webcam forprocessing?
Since I use Linux on my personal desktop (when not playing PC games) I chose touse the OpenCVpython bindings as I’m already familiar with them and they includeuseful image processing primatives in addition to V4L2 bindings for reading fromwebcams.
Reading a frame from the webcam with python-opencv
is very simple:
For better results with my camera before capturing set:
Most video conferencing software seems to cap video to 720p @ 30 FPS or lower,but we won’t necessarily read every frame anyhow, this sets an upper limit.
Put the frame capture in a loop and we’ve got our video feed!
We can save a test frame with just:
And now we can see that our camera works. Success!
# Finding The Background
OK, now that we have a video feed, how do we identify the background so we canreplace it? This is the tricky part …
While Zoom doesn’t seem to have commented anywhere about how they implementedthis, the way it behaves makes me suspect that a neural network is involved,it’s hard to explain but the results look like one.Additionally, I found an article about Microsoft Teams implementing background blur with a convolutional neural network.
Creating our own network wouldn’t be too hard in principle – There are manyarticles and papers on the topic of image segmentation and plenty of opensource libraries and tools, but we need a fairly specialized dataset to getgood results.
Specifically we’d need lots of webcam like images with the idealhuman foreground marked pixel by pixel versus the background.
Building this sort of dataset in prepartion for training a neural net probably wouldbe a lot of work. Thankfully a research team at Google has already done all of this hardwork and open sourced a pre-trained neural network for “person segmentation”called BodyPix that works pretty well! ❤️
BodyPix is currently only available in TensorFlow.js form, so the easiestway to use it is from the body-pix-node library.
To get faster inference (prediction) in the browser a WebGL backend is preferred, but innode we can use the Tensorflow GPU backend(NOTE: this requires a NVIDIA Graphics Card, which I have).
To make this easier to setup, we’ll start by setting up a small containerizedtensorflow-gpu + node environment / project. Using this with nvidia-docker ismuch easier than getting all of the right dependencies setup on your host, itonly requires docker and an up-to-date GPU driver on the host.
Now to serve the results… WARNING: I am not a node expert! This is justmy quick evening hack, bear with me :-)
The following simple script replies to an HTTP POST
ed image with a binary mask(an 2d array of binary pixels, where zero pixels are the background).
We can use numpy and requests to convert a frame to a mask from ourpython script with the following method:
Which gives us a result something like:
While I was working on this, I spotted this tweet:
This is definitely the BEST background for video calls. 💯 pic.twitter.com/Urz62Kg32k
— Ashley Willis (McNamara) (@ashleymcnamara) April 2, 2020Now that we have the foreground / background mask, it will be easy to replacethe background.
After grabbing the awesome “Virtual Background” picture from that twitter thread andcropping it to a 16:9 ratio image …
… we can do the following:
Which gives us:
The raw mask is clearly not tight enough due to the performance trade-offswe made with our BodyPix parameters but .. so far so good!
This background gave me an idea …
# Making It Fun
Now that we have the masking done, what can we do to make it look better?
Blur Mac Webcam Background Software Free
The first obvious step is to smooth the mask out, with something like:
This can help a bit, but it’s pretty minor and just replacing the backgroundis a little boring, since we’ve hacked this up ourselves we can do anythinginstead of just a basic background removal …
Given that we’re using a Star Wars “virtual background” I decided to createhologram effect to fit in better. This also lets lean into blurring the mask.
First update the post processing to:
Now the edges are blurry which is good, but we need to start building the hologrameffect.
Hollywood holograms typically have the following properties:
Webcam Blur Background
- washed out / monocrhomatic color, as if done with a bright laser
- scan lines or a grid like effect, as if many beams created the image
- “ghosting” as if the projection is done in layers or imperfectly reaching the correct distance
We can add these step by step.
First for the blue tint we just need to apply an OpenCV colormap:
Then we can add the scan lines with a halftone-like effect:
Next we can add some ghosting by adding weighted copies of the current effect,shifted along an axis:
Last: We’ll want to keep some of the original color, so let’s combinethe holo effect with the original frame similar to how we added the ghosting:
A frame with the hologram effect now looks like:
On it’s own this looks pretty :shrug:
But combined with our virtual background it looks more like:
There we go! :tada: (I promise it looks cooler with motion / video :upside_down_face:)
# Outputting Video
Now we’re just missing one thing … We can’t actually use this in a call yet.
To fix that, we’re going to use pyfakewebcam and v4l2loopback to create a fake webcam device.
We’re also going to actually wire this all up with docker.
First create a requirements.txt
with our dependencies:
And then the Dockerfile
for the fake camera app:
We’re going to need to install v4l2loopback
from a shell:
And then configure a fake camera device:
We need the exclusive_caps
setting for some apps (chrome, zoom) to work, the labelis just for our convenience when selecting the camera in apps, and the video numberjust makes this /dev/video20
if available, which is unlikely to be already in use.
Now we can update our script to create the fake camera:
We also need to note that pyfakewebcam
expects images in RGB
(red, green, blue)while our OpenCV operations are in BGR
(blue, green, red) channel order.
We can fix this before outputting and then send a frame with:
All together the script looks like:
Now build the images:
And run them like:
Now make sure to start this before opening the camera with any apps, andbe sure to select the “v4l2loopback” / /dev/video20
camera in Zoom etc.
# The Finished Result
Here’s a quick clip I recorded of this in action:
Look! I’m dialing into the millenium falcon with an open source camera stack!
I’m pretty happy with how this came out. I’ll definitely be joining all of my meetings this way in the morning. :grin:
Blurring your background makes your surroundings appear out of focus so people can't see what's going on behind you. Or maybe you just want to make it look like you're on a beach soaking up the sun. You can replace your surroundings with one of the preset backgrounds or an image of your own.
Make sure your device meets the following requirements:
Operating System—Windows 8 or Windows 10 32-bit/64-bit
Processor:
Intel Core i3, i5, or i7 4000 series or higher
AMD Ryzen 5, 7, 9, or higher
Memory:
8 GB or more of RAM
2 GB or more of VRAM for dedicated GPUs
1 | During a call or meeting, click your self-view video, and then choose Change Virtual Background. You can also personalize your background by uploading up to three of your own images. Click the + icon and then find the images you want to use. Supported file types are .jpg, .jpe, .jpeg, and .png. | ||
2 | Make your selection and then click Apply. Webex remembers your selection for your next call or meeting. Alternatively, you can click , click Change Virtual Background, make your selection, and then click Apply.
|