Skip to content

Latest commit

 

History

History
58 lines (40 loc) · 3.41 KB

backgroundnet.md

File metadata and controls

58 lines (40 loc) · 3.41 KB

Back | Next | Contents
Background Removal

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:

Running the Example

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.

Live Streaming

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