voelin-media: find the person for the studio's background replacement

Blur, image and colour backgrounds were cut around a centred oval: no
segmentation model was in the build. `segment::HumanSeg` (feature
`segment`, on by default) now runs PP-HumanSeg, PaddleSeg's portrait
segmentation model as OpenCV Zoo ships it (Apache-2.0, 6 MB, bundled in
crates/voelin-media/models with its licence and SHA-256), on the CPU with
tract-onnx: the frame squeezed to 192x192 RGB, the probability of a person
per pixel out as the mask. It is the default segmenter; the model is
parsed and optimised once per process on the segmentation thread, and if
it does not load the oval stands in. Builds without the feature keep the
oval.

One mask takes about 50 ms on one core (tract is optimised in dev builds
too, as voelin-media already is; unoptimised it took 430 ms), so the 10
masks a second cost about half a core. A new test checks the model loads,
the mask size, that an empty evenly lit room has next to nobody in it, and
the time per mask; the frame-path tests now use the oval explicitly, since
they need a mask known in advance. On a photo of a person the mask
follows the silhouette, arms and legs included (checked by eye; the photo
is not committed). Not yet tried with a camera.

The notices list the model and its licence; THIRD_PARTY_NOTICES.md is
regenerated for tract and its dependencies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
selikhovandClaude Opus 5.5 committed 2026-10-03 18:22:56 +03:00
1 parent 3e37c24836
commit 146502c9ca
12 files changed
+23838 -41

No files matched your search

+15 -8
View File
@@ -123,13 +123,19 @@ blur is a three-pass box blur (close to a Gaussian), separable, with a
running sum so its cost does not grow with the radius, in bands on a worker
pool over pooled buffers.
**What segments today is not a person.** `segment::Ellipse`, the segmenter
that is always there, is a centred oval about where a person sits in front
of a camera. A person segmentation model (MediaPipe selfie segmentation,
Apache-2.0, through `tract-onnx`) is meant to sit behind the `Segmenter`
trait; it is not in this build, because the model could not be fetched where
this was built (see [Status](#status)). Dropping it in changes nothing on the
frame path.
The person is found by `segment::HumanSeg` (feature `segment`, on by
default): PP-HumanSeg, PaddleSeg's portrait segmentation model as OpenCV Zoo
ships it (`crates/voelin-media/models/`, 6 MB, Apache-2.0, bundled into the
binary), run on the CPU by `tract-onnx`. The frame is squeezed to 192x192 RGB;
the mask is the model's probability of a person per pixel, 192x192, which
the frame path stretches back over the frame (its soft edge is the
feathering). The model is parsed and optimised once per process, on the
segmentation thread when the first mask is due; one mask then takes about
50 ms on one core of a desktop CPU (dev builds optimise tract too), so the
10 masks a second cost about half a core. If the model does not load,
`segment::Ellipse`, a centred oval about where a person sits in front of a
camera, stands in (and builds without `segment` use it). Other models drop
in behind the `Segmenter` trait without changing the frame path.
## Outputs (`studio::output`)
@@ -290,6 +296,7 @@ two threads) takes about 3 ms at its own rate (15 fps by default).
| Real camera through the user's PipeWire (Fifine K420, 1280x720) | `camera::tests::a_real_camera_delivers` (`--ignored`) | tested on one webcam |
| Camera through the XDG Camera portal (sandboxes) | – | compiles only |
| Screen, window and portal sources | the existing capture backends ([media.md](media.md#capture)) | as tested there; not run inside the studio here |
| Background blur, image and colour backdrops on the oval mask | `segment::tests` | tested; **no person segmentation model** (see above) |
| Background blur, image and colour backdrops on the oval mask | `segment::tests` | tested |
| Person segmentation (PP-HumanSeg through tract): loads, 192x192 mask, nobody in an empty room, time per mask | `segment::tests::the_model_finds_nobody_in_an_empty_room` | tested (about 50 ms per mask); on a photo of a person the mask follows the silhouette, arms and legs included (checked by eye, the photo is not in the repository); not yet tried with a camera |
| Windows and Android cameras | – | not implemented: `camera::list()` has only the test pattern there |
| RTMP | – | the seam only (refuses with its reason) |