A real-time vital signs monitoring system based on computer vision that enables contactless heart rate, SpO2, and respiration rate detection through webcam and Web API.
- 🎥 Real-time Video Processing - Real-time video frame capture and processing through webcam
- ❤️ Heart Rate Detection - Extract heart rate from facial video using POS (Plane-Orthogonal-to-Skin) algorithm
- 🩺 SpO2 Detection - Blood oxygen saturation detection based on red and green light signal ratios
- 🌬️ Respiration Rate Monitoring - Detect breathing frequency by analyzing facial region signal changes
- 👤 Face Detection & Tracking - Automatically detect and track faces, extract forehead and cheek regions
- 🌐 Web Interface - Intuitive real-time monitoring interface
- 🔒 CORS Support - Cross-origin access support
- .NET 10.0 - Backend framework
- OpenCvSharp 4.11.0 - Computer vision processing
- MathNet.Numerics 5.0.0 - Mathematical computation and signal processing (FFT, filtering, etc.)
- ASP.NET Core Web API - RESTful API service
- HTML5 + JavaScript - Frontend interface
- .NET 10.0 SDK or higher
- Windows OS (OpenCvSharp Windows runtime included)
- Webcam device
- Modern browser (WebRTC support)
git clone https://github.com/zhouda1fu/VitalSignsMonitor.git
cd VitalSignsMonitordotnet restoredotnet runOpen browser and visit: https://localhost:7104 or http://localhost:5180
- Start Application - Run
dotnet runto start the Web API service - Open Browser - Visit the application homepage
- Start Camera - Click "Start Camera" button and allow browser camera access
- Position Face - Ensure your face is clearly visible, the system will automatically detect it
- Wait for Initialization - The system needs about 1-2 seconds to collect data
- View Results - Real-time display of heart rate, SpO2, and respiration rate
- Face Detection - Use Haar cascade classifier to detect faces
- ROI Extraction - Extract forehead and cheek regions as regions of interest
- Skin Detection - Use YCrCb color space for skin region segmentation
- Signal Extraction - Calculate average RGB values of ROI regions
- POS Projection - Project RGB signals to a direction orthogonal to the skin plane
- Frequency Domain Analysis - Use FFT to analyze signals, find peak frequency in 0.75-3.0 Hz (45-180 BPM) range
- Signal Filtering - Apply bandpass filter (0.8-3.0 Hz) to red and green light signals
- AC/DC Calculation - Calculate AC and DC components
- Ratio Calculation - Calculate R value = (R_AC/R_DC) / (G_AC/G_DC)
- SpO2 Estimation - Use empirical formula: SpO2 = 105 - 20 × R
- Smoothing - Apply median filtering to smooth results
- Long Time Window - Use 30-second data window
- Resampling - Resample signal to 10 Hz
- Detrending - Remove trend using moving average window
- Frequency Domain Analysis - Find peak frequency in 0.15-0.5 Hz (9-30 breaths/min) range
Process video frame and return vital signs data.
Request Format:
- Content-Type:
multipart/form-data - Parameter:
frame(image file)
Response Format:
{
"heartRateBpm": 72.5,
"spO2Percent": 98.2,
"respirationRate": 16.3,
"status": "Measuring",
"hasFace": true
}Status Descriptions:
Initializing- System initializingGathering Data...- Collecting data (requires at least 1 second of data)No Face Detected- No face detectedNo Skin Detected- No skin region detectedMeasuring- Currently measuring
- Accuracy Limitations - This system is for research/demonstration purposes only and cannot replace professional medical equipment
- Environment Requirements - Requires good lighting conditions, avoid strong light and shadows
- Stability - Need to remain relatively still, minimize head movement
- Privacy - All video processing is done locally and not uploaded to server
- Performance - Modern CPU recommended, processing speed depends on hardware performance
Issues and Pull Requests are welcome!
This project is licensed under the MIT License. See LICENSE file for details.
- OpenCV - Computer vision library
- Math.NET Numerics - Mathematical computation library
- POS algorithm references related academic research
For questions or suggestions, please contact via GitHub Issues.
Disclaimer: This software is for research and educational purposes only and should not be used for medical diagnosis. Do not use in medical environments. Consult healthcare professionals for health concerns.
一个基于计算机视觉的实时生命体征监测系统,通过摄像头和 Web API 实现无接触式心率、血氧饱和度和呼吸率检测。
- 🎥 实时视频处理 - 通过摄像头实时捕获和处理视频帧
- ❤️ 心率检测 - 使用 POS (Plane-Orthogonal-to-Skin) 算法从面部视频中提取心率
- 🩺 血氧饱和度 (SpO2) - 基于红光和绿光信号比率的血氧检测
- 🌬️ 呼吸率监测 - 通过分析面部区域的信号变化检测呼吸频率
- 👤 人脸检测与跟踪 - 自动检测和跟踪人脸,提取前额和脸颊区域
- 🌐 Web 界面 - 提供直观的实时监测界面
- 🔒 CORS 支持 - 支持跨域访问
- .NET 10.0 - 后端框架
- OpenCvSharp 4.11.0 - 计算机视觉处理
- MathNet.Numerics 5.0.0 - 数学计算和信号处理(FFT、滤波等)
- ASP.NET Core Web API - RESTful API 服务
- HTML5 + JavaScript - 前端界面
- .NET 10.0 SDK 或更高版本
- Windows 操作系统(已包含 OpenCvSharp Windows 运行时)
- 摄像头设备
- 现代浏览器(支持 WebRTC)
git clone https://github.com/zhouda1fu/VitalSignsMonitor.git
cd VitalSignsMonitordotnet restoredotnet run打开浏览器访问:https://localhost:7104 或 http://localhost:5180
- 启动应用 - 运行
dotnet run启动 Web API 服务 - 打开浏览器 - 访问应用首页
- 启动摄像头 - 点击 "Start Camera" 按钮,允许浏览器访问摄像头
- 定位人脸 - 确保面部清晰可见,系统会自动检测人脸
- 等待初始化 - 系统需要约 1-2 秒收集数据
- 查看结果 - 实时显示心率、血氧饱和度和呼吸率
- 人脸检测 - 使用 Haar 级联分类器检测人脸
- ROI 提取 - 提取前额和脸颊区域作为感兴趣区域
- 皮肤检测 - 使用 YCrCb 颜色空间进行皮肤区域分割
- 信号提取 - 计算 ROI 区域的平均 RGB 值
- POS 投影 - 将 RGB 信号投影到与皮肤平面正交的方向
- 频域分析 - 使用 FFT 分析信号,在 0.75-3.0 Hz (45-180 BPM) 范围内查找峰值频率
- 信号滤波 - 对红光和绿光信号进行带通滤波 (0.8-3.0 Hz)
- AC/DC 计算 - 计算交流分量和直流分量
- 比率计算 - 计算 R 值 = (R_AC/R_DC) / (G_AC/G_DC)
- SpO2 估算 - 使用经验公式:SpO2 = 105 - 20 × R
- 平滑处理 - 使用中位数滤波平滑结果
- 长时间窗口 - 使用 30 秒的数据窗口
- 重采样 - 将信号重采样到 10 Hz
- 去趋势 - 使用移动平均窗口去除趋势
- 频域分析 - 在 0.15-0.5 Hz (9-30 次/分钟) 范围内查找峰值频率
处理视频帧并返回生命体征数据。
请求格式:
- Content-Type:
multipart/form-data - 参数:
frame(图像文件)
响应格式:
{
"heartRateBpm": 72.5,
"spO2Percent": 98.2,
"respirationRate": 16.3,
"status": "Measuring",
"hasFace": true
}状态说明:
Initializing- 系统初始化中Gathering Data...- 正在收集数据(需要至少 1 秒数据)No Face Detected- 未检测到人脸No Skin Detected- 未检测到皮肤区域Measuring- 正在测量
VitalSignsMonitor/
├── Controllers/
│ └── PulseController.cs # API 控制器
├── Services/
│ └── VitalSignsService.cs # 核心生命体征处理服务
├── wwwroot/
│ └── index.html # Web 前端界面
├── haarcascade_frontalface_alt.xml # 人脸检测分类器
├── Program.cs # 应用程序入口
└── VitalSignsMonitor.csproj # 项目配置文件
默认配置允许所有来源访问。在生产环境中,建议修改 Program.cs 中的 CORS 策略:
builder.AllowSpecificOrigins("https://yourdomain.com");当前 VitalSignsService 注册为 Singleton,适用于单用户场景。对于多用户生产环境,建议:
- 使用 Scoped 生命周期
- 为每个会话创建独立的服务实例
- 使用字典管理多个会话:
Dictionary<string, VitalSignsService>
- 心率缓冲区: 300 帧 (~10 秒 @ 30 FPS)
- 呼吸缓冲区: 900 帧 (~30 秒 @ 30 FPS)
- 心率: 0.75 - 3.0 Hz (45 - 180 BPM)
- 呼吸率: 0.15 - 0.5 Hz (9 - 30 次/分钟)
- 人脸检测间隔: 每 10 帧检测一次(已有人脸时)
- 人脸丢失阈值: 连续 30 帧未检测到人脸则重置
- 精度限制 - 此系统为研究/演示用途,不能替代专业医疗设备
- 环境要求 - 需要良好的光照条件,避免强光和阴影
- 稳定性 - 需要保持相对静止,减少头部移动
- 隐私 - 所有视频处理在本地完成,不会上传到服务器
- 性能 - 建议使用现代 CPU,处理速度取决于硬件性能
欢迎提交 Issue 和 Pull Request!
本项目采用 MIT 许可证。详见 LICENSE 文件。
- OpenCV - 计算机视觉库
- Math.NET Numerics - 数学计算库
- POS 算法参考相关学术研究
如有问题或建议,请通过 GitHub Issues 联系。
免责声明: 本软件仅供研究和教育用途,不能用于医疗诊断。请勿在医疗环境中使用,如有健康问题请咨询专业医疗人员。