How thearn/webcam-pulse-detector works
Project type and purpose
• This is a real-time computer-vision and signal-processing Python application.
• It captures video frames from a webcam or IP camera, detects a face, extracts a forehead ROI, measures optical intensity over time, computes heart rate, and renders both the video overlay and data plots.
File structure
• Entry point: get_pulse.py (orchestrates the pipeline and user controls).
• lib/device.py: abstracts video source (local webcam or IP camera).
• lib/interface.py: handles UI windows, keyboard events, and on-frame overlays.
• lib/processors.py: contains image-processing (face detection, ROI extraction) and signal-processing (raw intensity → filtered signal → BPM estimation).
• haarcascade_frontalface_alt.xml: OpenCV face-detection model.
• tests/test_processors.py: unit tests for processing algorithms.
• requirements.txt: Python dependencies (e.g., opencv-python, numpy, scipy, matplotlib).
Key insights from README
• Real-time signal-processing pipeline illustrated in README.
• Dependencies: OpenCV for image capture and face detection; NumPy/SciPy for numerical processing; Matplotlib (optional) for data plotting.
• Single-face support; optional locking of ROI; real-time overlay and data display toggled via keyboard.
Main components and their interactions
a. Video Source Component (lib/device.py)
• Inputs: local webcam or IP camera stream.
• Dependency: OpenCV VideoCapture.
b. Face Detection & ROI Extraction (lib/processors.py)
• Uses Haarcascade XML via OpenCV.
• Outputs the forehead region subimage each frame.
c. Data Acquisition & Buffering (lib/processors.py)
• Computes mean green-channel intensity per frame.
• Buffers a time series of intensities.
d. Signal Processing & Heart-Rate Estimation (lib/processors.py)
• Applies filtering to isolate pulse waveform.
• Computes power spectral density and detects BPM peak.
• Computes phase for real-time pulsing overlay.
e. UI/Interface Component (lib/interface.py)
• Renders data plot window (raw intensity, filtered signal, PSD).
• Handles user keyboard input (S to lock ROI, D to toggle data plot).
f. Controller/Orchestration (get_pulse.py)
• Initializes components, enters main loop: grab frame → process → render → handle events.
Architectural patterns and design principles
• Pipeline architecture: clear linear stages (Capture → Process → Output).
• Separation of concerns: device abstraction, processing logic, and UI are decoupled into separate modules.
• Configurability: parameters (data_spike_limit, buffer size) defined in get_pulse.py.
• Testability: processing functions covered by unit tests in tests/test_processors.py.
Essential elements
• Clear, concise labels for all components.
• Optionally, annotate performance-critical paths (e.g., face detection and filtering loop).