Back | Next | Contents
Background Removal
Background removal (aka background subtraction, or salient object detection) generates a mask that segments the foreground from the background of an image. You can use it to replace or blur backgrounds (similar to video conferencing applications), or it clould aid in pre-processing for other vision DNN's like object detection/tracking or motion detection. The model used is a fully-convolutional network U²-Net.
The backgroundNet
object takes an image, and outputs the foreground mask. backgroundNet
can be used from Python and C++.
As examples of using the backgroundNet
class, there are sample programs for C++ and Python:
backgroundnet.cpp
(C++)backgroundnet.py
(Python)
Here's an example of removing and replacing the background of an image:
# C++
$ ./backgroundnet images/bird_0.jpg images/test/bird_mask.png # remove the background (with alpha)
$ ./backgroundnet --replace=images/snow.jpg images/bird_0.jpg images/test/bird_replace.jpg # replace the background
# Python
$ ./backgroundnet.py images/bird_0.jpg images/test/bird_mask.png # remove the background (with alpha)
$ ./backgroundnet.py --replace=images/snow.jpg images/bird_0.jpg images/test/bird_replace.jpg # replace the background
The --replace
command-line argument accepts the filename of an image to replace the background with. It will be re-scaled to the same resolution as the input.
To run background removal or replacement on a live camera stream, pass in a device from the Camera Streaming and Multimedia page:
# C++
$ ./backgroundnet /dev/video0 # remove the background
$ ./backgroundnet --replace=images/coral.jpg /dev/video0 # replace the background
# Python
$ ./backgroundnet /dev/video0 # remove the background
$ ./backgroundnet --replace=images/coral.jpg /dev/video0 # replace the background
By specifying an output stream, you can view this on a display (the default), over the network (like with WebRTC), or save it to a video file.
Next | Monocular Depth Estimation
Back | Action Recognition
© 2016-2021 NVIDIA | Table of Contents