explaingit

peterl1n/backgroundmattingv2

7,163PythonAudience · researcherComplexity · 3/5LicenseSetup · hard

TLDR

Background Matting V2 is a research AI model that removes backgrounds from photos and videos in real time at up to 4K resolution, no green screen needed, just a clean reference photo of the empty background.

Mindmap

mindmap
  root((BG Matting V2))
    What it does
      Remove backgrounds
      No green screen needed
      Real-time processing
    Inputs needed
      Video or image
      Background reference photo
      Webcam option
    Model formats
      PyTorch
      TensorFlow
      ONNX
    Performance
      4K at 30 fps
      HD at 60 fps
      GPU required
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Remove the background from a recorded video using only a reference photo of the empty background.

USE CASE 2

Run real-time background removal on webcam footage at HD resolution for use in video calls.

USE CASE 3

Try the model in Google Colab without installing anything locally to evaluate whether it fits your use case.

USE CASE 4

Integrate the model into an existing ML pipeline using PyTorch, TensorFlow, or ONNX depending on your stack.

Tech stack

PythonPyTorchTensorFlowONNXTorchScriptCUDA

Getting it running

Difficulty · hard Time to first run · 1h+

Requires a high-end NVIDIA GPU with CUDA, CPU inference is not supported for real-time use.

Use freely for any purpose including commercial use, just keep the original copyright notice.

In plain English

Background matting is the process of separating a person or object from its background in a photo or video, without a green screen. This repository contains the code and pre-trained model weights for a research paper from the University of Washington on doing that separation in real time at high resolution. The paper received a Best Student Paper Honorable Mention at CVPR 2021, a major computer vision research conference. The approach requires one extra step compared to green-screen setups: before filming, you take a photo of the background without anyone in it. The model then compares that reference image to each frame of the video or image you want to process, using the difference to figure out what is subject and what is background. This technique lets the model run at 4K resolution at 30 frames per second, or at HD resolution at 60 frames per second, on a high-end consumer graphics card. The repository includes three scripts: one for processing a folder of images, one for processing a video file, and one for running interactively with a webcam. Google Colab notebooks are also provided so you can try the model online without installing anything locally. The model runs through PyTorch, TorchScript, TensorFlow, or ONNX, depending on what your existing workflow uses. Two datasets are published alongside the code: VideoMatte240K and PhotoMatte85. The README notes that the video processing scripts are for testing and experimentation only. They do not include hardware-accelerated encoding or decoding, so production use would require additional engineering beyond what the repository provides. A follow-up paper called Robust Video Matting improved on this work by removing the requirement for a background reference image entirely. A Linux plugin is also available that pipes webcam footage through the model for use in video calls. The project is released under the MIT License, which permits commercial use.

Copy-paste prompts

Prompt 1
I want to use Background Matting V2 to remove the background from a video file. Show me how to run the video processing script with a reference background image and what output it produces.
Prompt 2
I want to run Background Matting V2 on live webcam footage for a virtual background. Show me how to run the webcam script and what GPU hardware is required.
Prompt 3
I'm building a production video pipeline and want to integrate Background Matting V2. What does the model take as input and output, and which export format should I use for a TensorFlow serving setup?
Prompt 4
How does Background Matting V2 compare to the follow-up Robust Video Matting model, and when would I choose one over the other?
Open on GitHub → Explain another repo

← peterl1n on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.