What it does
The server captures frames with OpenCV, draws YOLO11 detections on the stream, and serves the result to any browser on the network. It started as a stream from an ESP32-CAM and grew into a general USB webcam server once the microcontroller's frame rate became the limit.
- Live video over MJPEG on the local network, with an authenticated web UI.
- YOLO11 ONNX inference at 640 px, with boxes, labels and per-class counts on frame.
- Continuous recording to disk, plus per-session playback at real-time pacing.
- Brightness, contrast and saturation controls that write straight to the camera.
- Single JPEG and WebSocket endpoints for clients that buffer or block MJPEG.
The tunnel problem
Cloudflare quick tunnels buffer multipart MJPEG, so a stream that is smooth on the LAN turns into a slideshow the moment it leaves the building. The page detects a trycloudflare.com hostname and switches to pushing individual JPEG frames over a WebSocket, with a polling fallback if the socket cannot connect.
That single decision is the difference between the camera being useful remotely and being useless, and it is the part that needed the most measurement rather than guesswork.
Detection tuning
Detection settings sit at the top of the server file so they can be changed without reading the pipeline: confidence 0.30, NMS 0.45, 640 px input, JPEG quality 70. YOLO11s at 640 px is noticeably more accurate on small objects; YOLO11n runs about three times faster and is the better choice when the machine is doing other work.
Every endpoint sits behind HTTP basic auth, with the credentials and model path supplied as environment variables so nothing sensitive is committed.