locaal-ai / obs-backgroundremoval

An OBS plugin for removing background in portrait images (video), making it easy to replace the background when recording or streaming.
GNU General Public License v2.0
2.96k stars 202 forks source link
background-segmentation computer-vision image-segmentation libobs mac-osx obs obs-plugin obs-studio obs-studio-plugin obsproject onnx onnx-runtime onnxruntime onnxruntime-gpu plugin video-segmentation

OBS Plugin: Portrait Background Removal / Virtual Green-screen and Low-Light Enhancement

[![GitHub](https://img.shields.io/github/license/locaal-ai/obs-backgroundremoval)](https://github.com/locaal-ai/obs-backgroundremoval/blob/main/LICENSE) [![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/locaal-ai/obs-backgroundremoval/push.yaml)](https://github.com/locaal-ai/obs-backgroundremoval/actions/workflows/push.yaml) [![Total downloads](https://img.shields.io/github/downloads/locaal-ai/obs-backgroundremoval/total)](https://github.com/locaal-ai/obs-backgroundremoval/releases) ![Flathub](https://img.shields.io/flathub/downloads/com.obsproject.Studio.Plugin.BackgroundRemoval?label=Flathub%20Installs) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/locaal-ai/obs-backgroundremoval)](https://github.com/locaal-ai/obs-backgroundremoval/releases) [![Discord](https://img.shields.io/discord/1200229425141252116)](https://discord.gg/KbjGU2vvUz)

A plugin for OBS Studio that allows you to replace the background in portrait images and video, as well as enhance low-light scenes.

For other AI plugins from us check out locaal AI.

Usage

Check out the usage guide page for usage walkthrough and recommendations.

Additional tutorial videos:

Download

Check out the guide page for downloads and install instructions for Windows and MacOS.

Linux Installation

On Ubuntu, there are two ways to install OBS and you have to use the corresponding method to install this plugin.

The pre-built binary of this plugin can run Ubuntu 22.04 or later.

On openSUSE, please see docs/BUILDING-OPENSUSE.md.

FlatHub

On Debian, you cannot use our deb package and we only support FlatHub installation.

On other Linux distros, use the FlatHub installation of both OBS and this plugin.

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
flatpak install flathub com.obsproject.Studio
flatpak install flathub com.obsproject.Studio.Plugin.BackgroundRemoval

If you install OBS in a way other than FlatHub, you have to build this plugin by yourself (see instructions for building below).

OBS Version Support and Compatibility

Introduction

This plugin is meant to make it easy to replace the background in portrait images and video. It is using a neural network to predict the mask of the portrait and remove the background pixels. It's easily composable with other OBS plugins to replace the background with e.g. an image or a transparent color.

If you like this work, which is given to you completely free of charge, please consider supporting it by sponsoring us on GitHub:

Support and Help

Reach out to us on Discord or the OBS Plugins forum for online / immediate help.

If you found a bug or want to suggest a feature or improvement please open an issue.

If you are looking for hands-on help or private consultation please select a sponsorship tier.

Technical Details

GPU support:

Number of CPU threads is controllable through the UI settings. A 2-thread setting works best.

The pretrained model weights used for portrait foreground segmentation are taken from:

Image enhancement (low light) models are taken from:

Some more information about how I built it: https://www.morethantechnical.com/2021/04/15/obs-plugin-for-portrait-background-removal-with-onnx-sinet-model/ and https://www.morethantechnical.com/2023/05/20/building-an-obs-background-removal-plugin-a-walkthrough/

Code Walkthrough

This video on YouTube will take you through the major parts of the code and explain them.

Building

The plugin was built and tested on Mac OSX (Intel & Apple silicon), Windows and several Linux disros (e.g. Ubuntu/Debian-ish, Fedora, and more). Help is appreciated in building on other OSs and packages.

The building pipelines in CI take care of the heavy lifting. Use them in order to build the plugin locally. We attempt to use external OpenCV, libcurl and ONNX Runtime to reduce build times.

Start by cloning this repo to a directory of your choice.

Mac OSX

Using the CI pipeline scripts, locally you would just call the zsh script. By default this builds a universal binary for both Intel and Apple Silicon. To build for a specific architecture please see .github/scripts/.build.zsh for the -arch options.

$ ./.github/scripts/build-macos -c Release

Install

The above script should succeed and the plugin files (e.g. obs-backgroundremoval.plugin) will reside in the ./release/Release folder off of the root. Copy the .plugin file to the OBS directory e.g. ~/Library/Application Support/obs-studio/plugins.

To get .pkg installer file, run for example

$ ./.github/scripts/package-macos -c Release

(Note that maybe the outputs will be in the Release folder and not the install folder like pakage-macos expects, so you will need to rename the folder from build_x86_64/Release to build_x86_64/install)

Linux

Ubuntu

Use the CI scripts again

$ ./.github/scripts/build-linux.sh

Arch Linux

The community maintains AUR packages: https://aur.archlinux.org/packages/obs-backgroundremoval

Fedora

To compile on Fedora, you need to manage the dependencies manually. See docs/BUILDING-FEDORA.md for more information.

FlatHub

The plugin is available on FlatHub: https://github.com/flathub/com.obsproject.Studio.Plugin.BackgroundRemoval

$ flatpak install com.obsproject.Studio.Plugin.BackgroundRemoval

Windows

Use the CI scripts again, for example:

> .github/scripts/Build-Windows.ps1 -Target x64 -CMakeGenerator "Visual Studio 17 2022"

The build should exist in the ./release folder off the root. You can manually install the files in the OBS directory.

Star History Chart