Skip to content

Minimal end-to-end prototype for macOS using one webcam + monocular depth in Python, streaming to a Three.js point-cloud viewer over WebSocket.

License

Notifications You must be signed in to change notification settings

sylwesterdigital/webcam-monocular-depth

Repository files navigation

LiveDepth

pointcloud_2025-09-27_00-08-53

LiveDepth is a real-time monocular depth streaming app for macOS.
It uses PyTorch MiDaS models to infer per-pixel depth from a webcam feed (or a synthetic test pattern), and streams results over WebSockets to a browser-based 3D viewer.

It runs locally, requires no cloud connection, and packages into a standalone .app with HTTPS UI and WSS data channel.


Features

  • Monocular depth estimation in real-time using MiDaS (MiDaS_small, DPT_Hybrid, or DPT_Large).
  • Camera feed (FaceTime HD, external USB, or virtual webcams) or synthetic test pattern.
  • Streams depth + RGB frames via WebSocket.
  • Local HTTPS server hosts the UI viewer.
  • Status-bar app bundle for macOS with:
    • Open Viewer
    • Restart Server
    • About panel (with version/build metadata)
    • Quit

Requirements

  • macOS 11.0+ (Apple Silicon recommended).
  • Python 3.10+ (tested with 3.13).
  • Homebrew (to install ffmpeg and mkcert).
  • Dependencies (install inside a venv):
  pip install opencv-python torch torchvision torchaudio pillow websockets numpy timm pyobjc

Running Locally (Source Tree)

1. Clone and set up environment

git clone https://github.com/sylwesterdigital/webcam-monocular-depth
cd webcam-monocular-depth
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

2. Generate HTTPS certificates (first run only)

cd client
mkdir -p certs && cd certs
brew install mkcert nss
mkcert -install
mkcert localhost 127.0.0.1 ::1

3. Test run (without build)

Use test pattern (no camera):

./test.sh

Or use webcam:

./test.sh --camera

This launches:


Building macOS .app

We use PyInstaller with a custom LiveDepth.spec.

1. Ensure you have pyinstaller

pip install pyinstaller

2. Create app icon

mkdir -p build/Icon.iconset assets
sips -z 16 16     icon.png --out build/Icon.iconset/icon_16x16.png
sips -z 32 32     icon.png --out build/Icon.iconset/[email protected]
sips -z 32 32     icon.png --out build/Icon.iconset/icon_32x32.png
sips -z 64 64     icon.png --out build/Icon.iconset/[email protected]
sips -z 128 128   icon.png --out build/Icon.iconset/icon_128x128.png
sips -z 256 256   icon.png --out build/Icon.iconset/[email protected]
sips -z 256 256   icon.png --out build/Icon.iconset/icon_256x256.png
sips -z 512 512   icon.png --out build/Icon.iconset/[email protected]
sips -z 512 512   icon.png --out build/Icon.iconset/icon_512x512.png
sips -z 1024 1024 icon.png --out build/Icon.iconset/[email protected]
iconutil -c icns build/Icon.iconset -o assets/LiveDepth.icns

3. Build

pyinstaller LiveDepth.spec --noconfirm

The result is in:

dist/LiveDepth.app

Move it to /Applications if desired.


Usage

  • Launch LiveDepth.app from Finder.

  • A status-bar icon appears (LiveDepth).

  • Menu options:

    • About LiveDepth — shows version/build info
    • Open Viewer — opens the browser client
    • Restart Server — restarts depth inference
    • Quit LiveDepth — exits

Configuration

Set via environment variables:

  • WEBCAM_INDEX=0 — select camera by index
  • WEBCAM_NAME="FaceTime HD Camera" — select camera by name (macOS/AVFoundation)
  • MODEL_TYPE=MiDaS_small|DPT_Hybrid|DPT_Large
  • TEST_PATTERN=1 — use synthetic scene (for debugging)
  • TARGET_WIDTH=640 — resize input width
  • STRIDE=2 — subsample for performance/bandwidth

License

© 2025 Sylwester Mielniczuk — WORKWORK.FUN LTD (UK). All rights reserved.

About

Minimal end-to-end prototype for macOS using one webcam + monocular depth in Python, streaming to a Three.js point-cloud viewer over WebSocket.

Resources

License

Stars

Watchers

Forks

Packages

No packages published