# royshil/obs-backgroundremoval architecture

> Architecture diagram of the GitHub repository royshil/obs-backgroundremoval, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/royshil/obs-backgroundremoval
- Repository: https://github.com/royshil/obs-backgroundremoval

## Overview

This repository is an OBS Studio plugin for portrait background removal and low-light enhancement. The primary workflow is an OBS video filter capturing a frame, running a selected model through ONNX Runtime, then rendering the processed result. Separate model adapters support segmentation, depth and enhancement; macOS also has a CoreML rendering pipeline. The README documents CPU/GPU acceleration and both product capabilities. Several macOS implementation files and model adapters were not sampled, so those branches are shown only where the tree or README supports them.

Main entry points: [`src/background-filter.cpp`](https://github.com/royshil/obs-backgroundremoval/blob/main/src/background-filter.cpp) (Background filter), [`src/enhance-filter.cpp`](https://github.com/royshil/obs-backgroundremoval/blob/main/src/enhance-filter.cpp) (Enhancement filter), [`src/plugin-main.cpp`](https://github.com/royshil/obs-backgroundremoval/blob/main/src/plugin-main.cpp) (Plugin registration), [`src/macos/BackgroundRemoval/MediaPipeLandscapePipeline.hpp`](https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/BackgroundRemoval/MediaPipeLandscapePipeline.hpp) (Landscape pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_plugin["OBS Plugin"]
  node_entry["Plugin registration<br/>[plugin-main.cpp]"]
  node_background["Background filter"]
  node_enhance["Enhancement filter<br/>[enhance-filter.cpp]"]
  node_frame["Filter frame data<br/>[FilterData.hpp]"]
  node_obsutils["OBS image capture<br/>[obs-utils.cpp]"]
end

subgraph group_inference["Inference"]
  node_session["ONNX sessions"]
  node_models["Model adapters<br/>[Model.hpp]"]
  node_segmodels["Segmentation models"]
  node_depthmodel["Depth model"]
  node_enhancemodels["Enhancement models<br/>[ModelTBEFN.hpp]"]
end

subgraph group_macos["macOS Rendering"]
  node_macfilter["macOS filter context<br/>[FilterContext.cpp]"]
  node_pipeline["Landscape pipeline"]
  node_imageproc["Mask processing"]
  node_mainfx["Render effect<br/>[MainEffect.cpp]"]
end

subgraph group_support["Plugin Support"]
  node_about["About dialog<br/>[AboutDialog.cpp]"]
  node_aboutlink["About integration"]
  node_updates["Update checker"]
  node_aligned["Aligned buffers<br/>[AlignedBuffer.cpp]"]
end

node_obs(("OBS user"))

node_obs -->|"uses plugin"| node_entry
node_entry -->|"registers filter"| node_background
node_entry -->|"registers filter"| node_enhance
node_background -->|"uses state"| node_frame
node_enhance -->|"uses state"| node_frame
node_background -->|"captures frames"| node_obsutils
node_enhance -->|"captures frames"| node_obsutils
node_background -->|"creates session"| node_session
node_enhance -->|"creates session"| node_session
node_session -->|"runs inference"| node_models
node_background -->|"selects model"| node_segmodels
node_background -->|"selects model"| node_depthmodel
node_enhance -->|"selects model"| node_enhancemodels
node_macfilter -->|"creates pipeline"| node_pipeline
node_pipeline -->|"processes masks"| node_imageproc
node_pipeline -.->|"renders effect"| node_mainfx
node_pipeline -->|"allocates buffers"| node_aligned
node_entry -->|"integrates dialog"| node_aboutlink
node_aboutlink -->|"opens dialog"| node_about
node_aboutlink -->|"checks versions"| node_updates
node_background -->|"checks versions"| node_updates
node_enhance -->|"checks versions"| node_updates

click node_entry "https://github.com/royshil/obs-backgroundremoval/blob/main/src/plugin-main.cpp"
click node_background "https://github.com/royshil/obs-backgroundremoval/blob/main/src/background-filter.cpp"
click node_enhance "https://github.com/royshil/obs-backgroundremoval/blob/main/src/enhance-filter.cpp"
click node_frame "https://github.com/royshil/obs-backgroundremoval/blob/main/src/FilterData.hpp"
click node_session "https://github.com/royshil/obs-backgroundremoval/blob/main/src/ort-utils/ort-session-utils.cpp"
click node_models "https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/Model.hpp"
click node_segmodels "https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/ModelSelfieMulticlass.hpp"
click node_depthmodel "https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/ModelTCMonoDepth.hpp"
click node_enhancemodels "https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/ModelTBEFN.hpp"
click node_obsutils "https://github.com/royshil/obs-backgroundremoval/blob/main/src/obs-utils/obs-utils.cpp"
click node_macfilter "https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/BackgroundRemoval/FilterContext.cpp"
click node_pipeline "https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/BackgroundRemoval/MediaPipeLandscapePipeline.hpp"
click node_imageproc "https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/ImageProcessing.hpp"
click node_mainfx "https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/BackgroundRemoval/MainEffect.cpp"
click node_about "https://github.com/royshil/obs-backgroundremoval/blob/main/src/UI/AboutDialog.cpp"
click node_aboutlink "https://github.com/royshil/obs-backgroundremoval/blob/main/src/UI/AboutDialogIntegration.cpp"
click node_updates "https://github.com/royshil/obs-backgroundremoval/blob/main/src/UpdateConfig/UpdateConfigCommon.cpp"
click node_aligned "https://github.com/royshil/obs-backgroundremoval/blob/main/src/Memory/AlignedBuffer.cpp"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_background,node_enhance,node_frame,node_obsutils,node_obs toneBlue
class node_session,node_models,node_segmodels,node_depthmodel,node_enhancemodels toneAmber
class node_macfilter,node_pipeline,node_imageproc,node_mainfx toneMint
class node_about,node_aboutlink,node_updates,node_aligned toneRose
```

## Components

### OBS Plugin

- [Plugin registration](https://github.com/royshil/obs-backgroundremoval/blob/main/src/plugin-main.cpp): `src/plugin-main.cpp`
- [Background filter](https://github.com/royshil/obs-backgroundremoval/blob/main/src/background-filter.cpp): `src/background-filter.cpp`
- [Enhancement filter](https://github.com/royshil/obs-backgroundremoval/blob/main/src/enhance-filter.cpp): `src/enhance-filter.cpp`
- [Filter frame data](https://github.com/royshil/obs-backgroundremoval/blob/main/src/FilterData.hpp): `src/FilterData.hpp`
- [OBS image capture](https://github.com/royshil/obs-backgroundremoval/blob/main/src/obs-utils/obs-utils.cpp): `src/obs-utils/obs-utils.cpp`

### Inference

- [ONNX sessions](https://github.com/royshil/obs-backgroundremoval/blob/main/src/ort-utils/ort-session-utils.cpp): `src/ort-utils/ort-session-utils.cpp`
- [Model adapters](https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/Model.hpp): `src/models/Model.hpp`
- [Segmentation models](https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/ModelSelfieMulticlass.hpp): `src/models/ModelSelfieMulticlass.hpp`
- [Depth model](https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/ModelTCMonoDepth.hpp): `src/models/ModelTCMonoDepth.hpp`
- [Enhancement models](https://github.com/royshil/obs-backgroundremoval/blob/main/src/models/ModelTBEFN.hpp): `src/models/ModelTBEFN.hpp`

### macOS Rendering

- [macOS filter context](https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/BackgroundRemoval/FilterContext.cpp): `src/macos/BackgroundRemoval/FilterContext.cpp`
- [Landscape pipeline](https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/BackgroundRemoval/MediaPipeLandscapePipeline.hpp): `src/macos/BackgroundRemoval/MediaPipeLandscapePipeline.hpp`
- [Mask processing](https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/ImageProcessing.hpp): `src/macos/ImageProcessing.hpp`
- [Render effect](https://github.com/royshil/obs-backgroundremoval/blob/main/src/macos/BackgroundRemoval/MainEffect.cpp): `src/macos/BackgroundRemoval/MainEffect.cpp`

### Plugin Support

- [About dialog](https://github.com/royshil/obs-backgroundremoval/blob/main/src/UI/AboutDialog.cpp): `src/UI/AboutDialog.cpp`
- [About integration](https://github.com/royshil/obs-backgroundremoval/blob/main/src/UI/AboutDialogIntegration.cpp): `src/UI/AboutDialogIntegration.cpp`
- [Update checker](https://github.com/royshil/obs-backgroundremoval/blob/main/src/UpdateConfig/UpdateConfigCommon.cpp): `src/UpdateConfig/UpdateConfigCommon.cpp`
- [Aligned buffers](https://github.com/royshil/obs-backgroundremoval/blob/main/src/Memory/AlignedBuffer.cpp): `src/Memory/AlignedBuffer.cpp`

### Other components

- **OBS user**

## Connections

- OBS user → Plugin registration: uses plugin
- Plugin registration → Background filter: registers filter (evidence: `src/plugin-main.cpp`)
- Plugin registration → Enhancement filter: registers filter (evidence: `src/plugin-main.cpp`)
- Background filter → Filter frame data: uses state (evidence: `src/FilterData.hpp`)
- Enhancement filter → Filter frame data: uses state (evidence: `src/FilterData.hpp`)
- Background filter → OBS image capture: captures frames (evidence: `src/background-filter.cpp`)
- Enhancement filter → OBS image capture: captures frames (evidence: `src/enhance-filter.cpp`)
- Background filter → ONNX sessions: creates session (evidence: `src/background-filter.cpp`)
- Enhancement filter → ONNX sessions: creates session (evidence: `src/enhance-filter.cpp`)
- ONNX sessions → Model adapters: runs inference (evidence: `src/ort-utils/ort-session-utils.cpp`)
- Background filter → Segmentation models: selects model (evidence: `src/background-filter.cpp`)
- Background filter → Depth model: selects model (evidence: `src/background-filter.cpp`)
- Enhancement filter → Enhancement models: selects model (evidence: `src/enhance-filter.cpp`)
- macOS filter context → Landscape pipeline: creates pipeline (evidence: `src/macos/BackgroundRemoval/FilterContext.cpp`)
- Landscape pipeline → Mask processing: processes masks (evidence: `src/macos/BackgroundRemoval/MediaPipeLandscapePipeline.hpp`)
- Landscape pipeline → Render effect: renders effect
- Landscape pipeline → Aligned buffers: allocates buffers (evidence: `src/macos/BackgroundRemoval/MediaPipeLandscapePipeline.hpp`)
- Plugin registration → About integration: integrates dialog (evidence: `src/plugin-main.cpp`)
- About integration → About dialog: opens dialog (evidence: `src/UI/AboutDialogIntegration.cpp`)
- About integration → Update checker: checks versions (evidence: `src/UI/AboutDialogIntegration.cpp`)
- Background filter → Update checker: checks versions (evidence: `src/background-filter.cpp`)
- Enhancement filter → Update checker: checks versions (evidence: `src/enhance-filter.cpp`)
