Featuring Live Camera Detection and an Interactive Simulator
Live Metrics
Status: Stopped
Respiration Rate: -- BPM
Breaths Detected: 0
Signal Quality: --
Sound:
Mode:
Simulation
Sensitivity:1.8x
Overview
This application measures breathing rate using computer vision. It features two modes: a Live
Camera Mode that uses your webcam and a machine learning model to detect your breathing in
real-time, and a Simulation Mode that visualizes pre-generated data for a consistent
educational experience.
How to Use
Choose a Mode: Use the "Mode" toggle to switch between "Simulation" and "Live
Camera".
In Simulation Mode: Click "Play Simulation" to start the animation. The sensitivity
slider is disabled in this mode as the data is clean.
In Live Camera Mode: Click "Start Camera" and grant webcam access. Position
yourself so your upper body is visible and stable.
Adjust Sensitivity: If breaths are not being detected (e.g., you are breathing very
shallowly), slowly increase the "Sensitivity" slider. If you see too many false detections from
small movements, decrease it. Finding the right balance is key!
Controls: Use the on-screen buttons or keyboard shortcuts (Spacebar for
Play/Pause/Start/Stop, R for Reset) to control the application.
Technical Details
Live Camera Mode: This mode uses Google's MediaPipe Pose, a
machine learning model that runs in your browser to detect 33 body landmarks from the webcam feed.
Signal vs. Noise & Sensitivity: The rhythmic vertical movement of your chest is the
"signal" we want to measure. However, small, random movements from body sways, camera jitter, or
digital video artifacts create "noise". The Sensitivity slider amplifies the
difference between the current signal and its recent average.
A high sensitivity can lift a weak breathing signal out of the noise floor, making it
detectable.
However, too much sensitivity will amplify the noise itself, causing the algorithm to detect
false breaths on random movements. This demonstrates the core trade-off in bio-signal
processing.
Camera Distance & Signal Quality: The quality of measurement depends heavily on
camera positioning:
Optimal: Position yourself so your hips are visible in the
frame. The system measures the torso height (distance from hips to shoulders), which is
robust to body sway and provides accurate breathing detection.
Too Close: If you're very close to the camera and your hips leave the
frame, the system falls back to measuring absolute shoulder position. This includes swaying,
leaning, and other body movementsânot just breathing. The "Signal Quality" indicator may
still show as "Good" (because it detects peaks), but the actual respiration rate accuracy is
compromised. Move back a bit if you see "Tracking Shoulders (Hips not visible)".
Unified Signal Processing: Both modes feed landmark data into the same processing
pipeline, which includes amplification (live mode only), a moving average filter for smoothing,
adaptive peak detection to count breaths, and rate calculation.
Tuning for Your Setup
If the app is missing breaths or showing false detections, here's how to debug:
False detections when holding breath (no movement): This is the hardest case
because the signal is pure noise. The app uses an adaptive threshold to distinguish breathing from
noise, but very strict thresholds (75%+) mean you need clear, deliberate breathing motion.
Solutions:
Ensure your hips are visible on camera (use "Tracking Torso" mode, not "Tracking
Shoulders").
Breathe more deliberatelyâdeeper inhales and exhales create stronger signals.
Try the 4-4-4 breathing pattern (inhale 4 counts, hold 4 counts, exhale 4 counts) to test
with controlled, obvious breathing.
If still getting false counts during held breath, lower the sensitivity slider or try
sitting perfectly still.
Missing real breaths: Your breathing signal is too weak or the threshold is too
strict. Try increasing sensitivity or breathing more deliberately (deeper inhales/exhales).
Why stricter defaults now: The threshold was increased from 0.65 to 0.75, and
minimum breath interval from 1.5s to 2.5s, to reduce false detections. This means fewer breaths will
be counted, but they'll be more accurate.
Code tuning: Advanced users can adjust:
BREATH_THRESHOLD_PERCENTILE (currently 0.75): Increase to 0.80â0.85 for even
stricter detection; decrease to 0.70 if missing breaths.
MIN_BREATH_INTERVAL (currently 2500ms): Increase to add more time between
detections; decrease to allow faster breathing patterns.
BANDPASS_LONG_WINDOW and BANDPASS_SHORT_WINDOW if your breathing
frequency differs from ~15 BPM.
Limitation: Breath detection from video is fundamentally challenging. When you hold your
breath completely still, the signal contains only noiseâno algorithm can reliably distinguish "held
breath" from "stationary person." The app is designed for detecting actual breathing motion, especially
when diaphragmatic movement is visible in the torso.
To verify that the app is measuring your breathing accurately, compare it against manual breath counting:
Simple Method: Breathe naturally, then count the number of breaths you take over 60
seconds. Divide by the time in minutes to get breaths per minute. Compare this to the app's BPM
reading.
Controlled Method (4-4-4 Breathing): Follow this pattern: inhale for 4 counts, hold
for 4 counts, exhale for 4 counts. This produces approximately 9 BPMâan easy baseline to verify.
This breathing pattern is also commonly used in meditation and mindfulness practice.
Consistency Check: Run multiple tests at different times. Your breathing rate
naturally varies based on activity level, stress, and relaxation. Resting breathing is typically
12â20 BPM; light exercise raises it to 25â40 BPM.
Meditation & Biofeedback
This application can serve as a biofeedback tool for meditation and breathwork practice. Meditation
typically involves slow, deep breathingâoften in the 4â8 BPM range (achieved through extended inhales
and exhales). By watching the app's real-time display and waveform, you can:
Maintain a steady, controlled breathing pattern during your practice.
Observe how your breath naturally changes (e.g., becoming more regular as you relax).
Practice breath awareness by comparing what you feel internally to what the app detects externally.
Disclaimer: This is an educational tool, not a medical device. It demonstrates computer
vision and signal processing concepts. Any therapeutic benefits of breathing practices should be
verified through medical or clinical guidance, not from this app alone.
Known Limitations
Breath Detection Accuracy: Video-based breath detection relies on visible torso
motion. Conditions that reduce accuracy:
Shallow breathing: If your breathing is minimal (chest barely moves), the
app may not detect it. This is especially true if your clothing dampens the visual motion.
Held breath with stillness: When holding your breath completely still, the
only signal is camera noise. No algorithm can reliably distinguish this from stationary
rest.
Tight clothing or obscured torso: Loose-fitting clothing makes breathing
motion more visible.
Poor lighting: MediaPipe's landmark detection is robust but works best in
good lighting conditions.
Camera Positioning: Optimal results require your hips to be visible for the more
robust torso-height measurement. Too close, and the system falls back to shoulder tracking (less
accurate).
Breathing Rate Range: Detection is optimized for resting-to-moderate breathing
(8â40 BPM). Very fast breathing (panic, exercise at high intensity) or extremely slow breathing
(meditation <5 BPM) may not be reliably detected without adjustment.
Individual Variability: Every person breathes differently. Some have subtle chest
motion; others have obvious abdominal motion. Tuning sensitivity is often necessary.
Future Directions
This application serves as a foundation for more advanced features. Future development could include:
Multiple Scenarios: Adding buttons to switch between different synthetic data sets,
such as "Relaxed Breathing (12 BPM)", "Post-Exercise (25 BPM)", or "Irregular Breathing".
Heart Rate Estimation (rPPG): Implementing an algorithm in Live Mode to detect
subtle color changes in the user's forehead (caused by blood flow) to estimate heart rate.
Stress Level Analysis: Correlating breathing rate, regularity, and heart rate
variability (HRV) to provide a potential stress indicator.
Data Export: Allowing users to download their session data (BPM over time, breath
intervals) as a CSV file for analysis.
Guided Breathing Exercises: Creating a biofeedback mode with a visual guide (e.g.,
an expanding and contracting circle) to help users practice calming breathing techniques like box
breathing.