基於 OpenCV 人臉檢測和 POS 算法
- 🎯 自包含實現 - 不依賴有問題的外部庫,完全自主實現
- 👥 可靠的人臉檢測 - 使用 OpenCV Haar 級聯,支援多參數組合
- 💓 POS 算法 - Plane-Orthogonal-to-Skin 方法,提供穩健的心率估測
- 📊 即時進度更新 - Console 和 GUI 雙重進度顯示
- 🔍 人臉檢測測試 - 預先檢查影片是否適合分析
- 📈 資料匯出 - 下載心率圖表和 CSV 資料
- ⚡ 高效處理 - 分段處理,2分鐘影片約 30 秒完成
# 安裝依賴套件
pip install gradio opencv-python numpy scipy matplotlib tqdm
# 執行應用程式
python app.py在瀏覽器中開啟 http://127.0.0.1:7860
- 上傳包含清晰正面人臉的影片檔案
- 調整參數(預設值通常已足夠)
- 點擊「Process Video」開始分析
- 查看結果並下載資料
- 上傳影片進行人臉檢測測試
- 點擊「Test Face Detection」
- 確認影片是否適合進行心率分析
- 方法 (Method): POS (Plane-Orthogonal-to-Skin) - 目前唯一實現的方法
- 視窗 (Window): 心率計算的時間窗口 (5-30秒,預設: 10秒)
- 步長 (Step): 更新間隔 (0.5-5秒,預設: 2秒)
- 心率範圍 (Min/Max BPM): 心率過濾範圍 (預設: 45-180 BPM)
- 信心閾值 (Confidence Threshold): 有效讀數的最低信心值 (0.0-1.0,預設: 0.3)
- 清晰正面人臉: 人臉應清楚可見且面向攝影機
- 良好光線: 充足的光線,避免強烈陰影
- 最小移動: 避免過度的頭部移動或攝影機晃動
- 影片長度: 至少 30 秒以獲得可靠測量
- 解析度: 較高解析度通常效果更好
- 分段處理: 使用滑動窗口,避免逐幀處理
- 智能終止: 找到足夠測量值後自動停止
- 跳躍讀取: 直接跳到目標幀,提高效率
- 雙重進度: Console 和 GUI 進度條同步顯示
A simple and effective implementation for estimating heart rate from video using remote photoplethysmography (rPPG) with OpenCV face detection and POS algorithm.
- 🎯 Self-contained rPPG implementation - No dependency on problematic external libraries
- 👥 Reliable face detection - Uses OpenCV Haar cascades with multiple parameter sets
- 💓 POS algorithm - Plane-Orthogonal-to-Skin method for robust heart rate estimation
- 📊 Real-time progress updates - Console and GUI dual progress display
- 🔍 Face detection test - Pre-check videos for suitability before processing
- 📈 Export capabilities - Download heart rate plots and CSV data
- ⚡ Efficient processing - Chunk-based processing, ~30 seconds for 2-minute video
# Install dependencies
pip install gradio opencv-python numpy scipy matplotlib tqdm
# Run the application
python app.pyAccess the web interface at http://127.0.0.1:7860
- Upload a video file containing a clear frontal face
- Adjust parameters if needed (defaults work well)
- Click "Process Video" to start analysis
- View results and download data
- Upload a video to test face detection capability
- Click "Test Face Detection"
- Check if your video is suitable for heart rate analysis
- Method: POS (Plane-Orthogonal-to-Skin) - Currently the only implemented method
- Window: Time window for heart rate calculation (5-30 seconds, default: 10s)
- Step: Update interval (0.5-5 seconds, default: 2s)
- Min/Max BPM: Heart rate range filter (default: 45-180 BPM)
- Confidence Threshold: Minimum confidence for valid readings (0.0-1.0, default: 0.3)
- Clear frontal face: Face should be clearly visible and facing the camera
- Good lighting: Adequate lighting without harsh shadows
- Minimal movement: Avoid excessive head movement or camera shake
- Duration: At least 30 seconds for reliable measurements
- Resolution: Higher resolution generally works better
- Chunk-based processing: Uses sliding windows, avoids frame-by-frame processing
- Smart termination: Automatically stops after finding sufficient measurements
- Jump reading: Directly jumps to target frames for improved efficiency
- Dual progress: Console and GUI progress bars synchronized
- Face Detection: OpenCV Haar cascade classifiers with multiple parameter sets
- ROI Extraction: Forehead and cheek regions for optimal signal quality
- Signal Processing: POS algorithm with temporal bandpass filtering
- Heart Rate Estimation: FFT-based frequency domain analysis
- Face Detection: Detect faces using OpenCV with fallback parameters
- ROI Selection: Extract regions of interest from detected faces
- Signal Extraction: Compute mean RGB values from ROI
- POS Processing: Apply Plane-Orthogonal-to-Skin algorithm
- Filtering: Bandpass filter to isolate heart rate frequencies
- Estimation: FFT analysis to find dominant frequency (heart rate)
- Ensure face is clearly visible and frontal
- Check lighting conditions
- Try the face detection test first
- Consider different camera angles
- Reduce confidence threshold
- Increase window size
- Check for excessive movement
- Ensure adequate video length
- Improve lighting conditions
- Reduce head/camera movement
- Use longer analysis windows
- Check face visibility throughout video
app.py- Main Gradio application with rPPG implementationrequirements.txt- Python dependenciesREADME.md- This documentation- Archive files (app_old.py, etc.) - Previous VitalLens-based implementations
- Reliable face detection - No mysterious "No faces found" errors
- Self-contained - No external library dependencies with compatibility issues
- Transparent processing - Clear understanding of each processing step
- Better error handling - Informative feedback when processing fails
- Customizable - Easy to modify algorithm parameters and methods
- Efficient processing - Optimized chunk-based algorithm for faster results