Repository navigation
Conversation
- Implement background swapper frame processor using ONNX portrait matting - Add 3D perspective and translation parallax warping based on viewer point of view - Add background selection UI and toggle in PySide6 main window - Support background swap in live webcam preview, offline video/image processing, and CLI - Add unit tests for perspective rendering and blending Co-authored-by: art-e-ui <269083712+art-e-ui@users.noreply.github.com>
Co-authored-by: art-e-ui <269083712+art-e-ui@users.noreply.github.com>
- Add pyvirtualcam integration to stream processed live frames - Add Virtual Camera toggle switch and device selector in UI - Add --virtual-camera and --virtual-camera-device CLI flags - Add unit tests for virtual camera manager Co-authored-by: art-e-ui <269083712+art-e-ui@users.noreply.github.com>
- Add background swapper frame processor using ONNX portrait matting - Implement 3D perspective and translation parallax homography based on viewer point of view - Add pyvirtualcam virtual camera output for live preview - Add UI controls for background selection, background swap toggle, virtual camera toggle, and device selector - Add CLI options -b/--background, --background-swap, --virtual-camera, and --virtual-camera-device - Add comprehensive unit tests and pass ruff lint checks Co-authored-by: art-e-ui <269083712+art-e-ui@users.noreply.github.com>
Reviewer's GuideThis PR adds an end-to-end background-swap processor based on MODNet segmentation and pose-responsive perspective/parallax compositing, exposes it through CLI and UI controls, and adds optional pyvirtualcam output for processed live video with device selection, persistence, lifecycle management, and tests. Sequence diagram for background swapping a processed framesequenceDiagram
participant Input as Input Frame
participant Processor as background_swapper
participant Face as get_one_face
participant Matte as predict_matte
participant Model as MODNet ONNX
participant Background as get_background_image
participant Warp as render_3d_perspective_background
Input->>Processor: swap_background(frame, target_face)
Processor->>Background: get_background_image()
Processor->>Face: get_one_face(frame)
Processor->>Processor: compute_viewer_pov(face, frame_shape)
Processor->>Warp: render_3d_perspective_background(background, shape, dx, dy, yaw, pitch, roll)
Processor->>Matte: predict_matte(frame)
Matte->>Model: sess.run(input)
Model-->>Matte: portrait matte
Matte-->>Processor: alpha mask
Processor-->>Input: alpha-composited frame
Sequence diagram for routing live frames to a virtual camerasequenceDiagram
participant Capture as Live Capture
participant Preview as Webcam Preview
participant Manager as VIRTUAL_CAM
participant Device as Virtual Camera Device
Preview->>Manager: start(width, height, fps, device)
Manager->>Device: pyvirtualcam.Camera(...)
Device-->>Manager: camera handle
Capture->>Preview: processed BGR frame
Preview->>Manager: send_bgr_frame(raw_bgr_frame)
Manager->>Manager: cv2.cvtColor(bgr_frame, BGR2RGB)
Manager->>Device: send(rgb_frame)
Device-->>Preview: live virtual-camera output
Preview->>Manager: stop()
Manager->>Device: close()
Flow diagram for enabling background swapflowchart LR
CLI[CLI or UI background selection] --> State[background_path and background_swap]
State --> ProcessorList[frame_processors]
ProcessorList --> BackgroundSwapper[background_swapper]
BackgroundSwapper --> PreCheck[pre_check]
PreCheck --> Model[MODNet model]
BackgroundSwapper --> Process[process_frame or process_image]
Process --> Output[Processed image or video frame]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="modules/virtual_camera.py" line_range="47-48" />
<code_context>
+ system = platform.system()
+ if system == "Linux":
+ # Search for v4l2 video loopback devices
+ for dev in sorted(glob.glob("/dev/video*")):
+ devices.append(dev)
+ elif system == "Windows":
+ # Common Windows virtual camera driver names
</code_context>
<issue_to_address>
**Physical cameras appear as outputs**
When a Linux system has ordinary cameras alongside virtual-camera loopbacks, `get_available_devices` lists every `/dev/video*` node, including capture-only cameras. Selecting one passes it to `pyvirtualcam.Camera`, which cannot start output on it.
Filter Linux device discovery to include only virtual-camera loopback devices.
Also at `modules/virtual_camera.py:73-74`.
</issue_to_address>
### Comment 2
<location path="tests/test_virtual_camera.py" line_range="38" />
<code_context>
+ frame[:] = (255, 0, 0) # BGR blue
+ sent = self.manager.send_bgr_frame(frame)
+ self.assertTrue(sent)
+ self.assertTrue(mock_cam.send.called)
+
+ # Stop camera
</code_context>
<issue_to_address>
**Sent frame color can be wrong**
When `send_bgr_frame` sends frames without converting BGR to RGB, `test_start_and_send_frame` only checks that `mock_cam.send` was called, so a broken BGR-to-RGB conversion still passes; the test does not establish that the virtual camera receives correctly ordered color channels.
Inspect the array passed to `mock_cam.send` and assert its channel values are in RGB order.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and when enabled, processed live camera frames are sent to a virtual camera that other applications can consume or record; stopping or reverting the feature cannot recall frames already captured. The new pyvirtualcam dependency also adds a third-party runtime component.
Blocking findings: modules/virtual_camera.py:48, tests/test_virtual_camera.py:38
| for dev in sorted(glob.glob("/dev/video*")): | ||
| devices.append(dev) |
There was a problem hiding this comment.
🟡 Medium · Physical cameras appear as outputs
When a Linux system has ordinary cameras alongside virtual-camera loopbacks, get_available_devices lists every /dev/video* node, including capture-only cameras. Selecting one passes it to pyvirtualcam.Camera, which cannot start output on it.
Filter Linux device discovery to include only virtual-camera loopback devices.
Also at modules/virtual_camera.py:73-74.
Prompt for AI agents
In `modules/virtual_camera.py` at lines 47-48:
**Physical cameras appear as outputs**
When a Linux system has ordinary cameras alongside virtual-camera loopbacks, `get_available_devices` lists every `/dev/video*` node, including capture-only cameras. Selecting one passes it to `pyvirtualcam.Camera`, which cannot start output on it.
Filter Linux device discovery to include only virtual-camera loopback devices.
Also at `modules/virtual_camera.py:73-74`.| frame[:] = (255, 0, 0) # BGR blue | ||
| sent = self.manager.send_bgr_frame(frame) | ||
| self.assertTrue(sent) | ||
| self.assertTrue(mock_cam.send.called) |
There was a problem hiding this comment.
🟡 Medium · Sent frame color can be wrong
When send_bgr_frame sends frames without converting BGR to RGB, test_start_and_send_frame only checks that mock_cam.send was called, so a broken BGR-to-RGB conversion still passes; the test does not establish that the virtual camera receives correctly ordered color channels.
Inspect the array passed to mock_cam.send and assert its channel values are in RGB order.
Prompt for AI agents
In `tests/test_virtual_camera.py` at line 38:
**Sent frame color can be wrong**
When `send_bgr_frame` sends frames without converting BGR to RGB, `test_start_and_send_frame` only checks that `mock_cam.send` was called, so a broken BGR-to-RGB conversion still passes; the test does not establish that the virtual camera receives correctly ordered color channels.
Inspect the array passed to `mock_cam.send` and assert its channel values are in RGB order.
Summary by Sourcery
Add background replacement with parallax effects and virtual-camera output across processing, live preview, and user interfaces.
New Features:
Enhancements:
Build:
Tests: