← Back to list

Health Monitoring System to Track Breathing Patterns using Intel RealSense D435i Depth Camera

The project is focused on developing a Health Monitoring System that tracks breathing patterns using the Intel RealSense Depth Camera…

Sameera Pasan · 2024-08-24 04:35 · 1 claps · 5.4 min read
#intel #depth-cameras #embedded-systems #realsense #health-monitoring
Open on Medium ↗
Wiki topics: ⏱️ · Productivity 📷 · Photography

Health Monitoring System to Track Breathing Patterns using Intel RealSense D435i Depth Camera

The project is focused on developing a Health Monitoring System that tracks breathing patterns using the Intel RealSense Depth Camera D435i. The system captures depth data from a specific region of interest (the chest area) and analyzes the changes in depth over time to detect the rise and fall of the chest during breathing. This allows the system to monitor the breathing rate and pattern, which can be useful in various healthcare applications, such as tracking respiratory conditions or providing real-time alerts in case of irregular breathing.

The project involves:

  1. Capturing Depth Data: Using the Intel RealSense D435i camera to capture depth information from the chest area.
  2. Processing Data: Analyzing the depth changes to determine the breathing patterns.
  3. Visualizing Breathing Patterns: Plotting the data to visualize how the breathing pattern changes over time.
  4. Applications: This system can be used in healthcare settings to monitor patients, especially those with respiratory conditions, in a non-intrusive way.

What is a Depth Camera?

A depth camera is a type of camera that captures not just the color and intensity of light (as in traditional cameras) but also the distance of objects from the camera. This is achieved by measuring the time it takes for light (or an infrared signal) to travel from the camera, bounce off an object, and return to the camera. The result is a depth map, which represents the distance of each point in the scene from the camera. Depth cameras are commonly used in applications like 3D modeling, gesture recognition, and augmented reality.

What is the Intel RealSense Depth Camera D435i?

Intel RealSense Depth Camera D435i

Intel RealSense Depth Camera D435i

The Intel RealSense Depth Camera D435i is a high-quality depth-sensing camera designed by Intel. It is part of the RealSense family, known for its advanced 3D depth sensing and computer vision capabilities.

Key features of the D435i:

  • Stereo Depth Sensing: Uses two cameras (stereo vision) to calculate depth by comparing images from slightly different perspectives.
  • IMU (Inertial Measurement Unit): Includes an IMU to provide motion and orientation data, which is useful for tracking movement and stabilizing depth data.
  • High Resolution and Frame Rate: Offers depth resolution of up to 1280x720 at 30 frames per second, making it suitable for detailed and responsive depth sensing.
  • Versatile Use Cases: Commonly used in robotics, 3D scanning, virtual and augmented reality, and interactive systems where understanding the depth and structure of a scene is essential.

Hardware Setup

Hardware Setup

  1. Hardware Setup Intel RealSense D435i Depth Camera Computer/Laptop: To run the code and process data. Mounting Hardware: To position the camera for optimal capture of chest movements.

2. Software Requirements Intel RealSense SDK: For accessing and controlling the depth camera. Python: For coding and data processing. OpenCV: For image processing tasks. Numpy: For numerical operations. Matplotlib (Optional): For visualizing the breathing patterns.

3. Installation and Setup

Install the Intel RealSense SDK:

pip install pyrealsense2

Install additional Python libraries:

pip install opencv-python numpy matplotlib

4. Code Implementation

4.1. Initializing the Depth Camera

import pyrealsense2 as rs
import numpy as np
import cv2

# Initialize the camera pipeline
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)

# Start the camera
pipeline.start(config)

try:
    while True:
        # Wait for a frame
        frames = pipeline.wait_for_frames()
        depth_frame = frames.get_depth_frame()
        if not depth_frame:
            continue

        # Convert depth frame to numpy array
        depth_image = np.asanyarray(depth_frame.get_data())

        # Show depth image (optional)
        cv2.imshow('Depth Image', depth_image)

        # Exit on pressing 'q'
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

finally:
    # Stop the camera
    pipeline.stop()
    cv2.destroyAllWindows()

4.2. Processing Depth Data to Track Chest Movement

import time

# Region of interest (ROI) for the chest area (define based on camera placement)
ROI_TOP_LEFT = (200, 150)
ROI_BOTTOM_RIGHT = (440, 300)

# Variables for breathing pattern tracking
previous_avg_depth = None
breath_data = []

def calculate_average_depth(depth_image, roi_top_left, roi_bottom_right):
    roi = depth_image[roi_top_left[1]:roi_bottom_right[1], roi_top_left[0]:roi_bottom_right[0]]
    avg_depth = np.mean(roi)
    return avg_depth

try:
    start_time = time.time()

    while True:
        frames = pipeline.wait_for_frames()
        depth_frame = frames.get_depth_frame()
        if not depth_frame:
            continue

        depth_image = np.asanyarray(depth_frame.get_data())

        # Calculate the average depth in the chest area
        avg_depth = calculate_average_depth(depth_image, ROI_TOP_LEFT, ROI_BOTTOM_RIGHT)

        if previous_avg_depth is not None:
            # Calculate the change in depth (chest movement)
            depth_change = previous_avg_depth - avg_depth
            breath_data.append((time.time() - start_time, depth_change))

            # Simple breathing detection (when chest moves outward)
            if depth_change > 0:
                print("Breath In")
            elif depth_change < 0:
                print("Breath Out")

        previous_avg_depth = avg_depth

        cv2.rectangle(depth_image, ROI_TOP_LEFT, ROI_BOTTOM_RIGHT, (255, 0, 0), 2)
        cv2.imshow('Depth Image', depth_image)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

finally:
    pipeline.stop()
    cv2.destroyAllWindows()

4.3. Analyzing and Visualizing Breathing Patterns

import matplotlib.pyplot as plt

# Convert the collected data into time and depth change arrays
times, depth_changes = zip(*breath_data)

# Plot the breathing pattern
plt.figure(figsize=(10, 5))
plt.plot(times, depth_changes, label='Chest Movement')
plt.xlabel('Time (s)')
plt.ylabel('Depth Change (mm)')
plt.title('Breathing Pattern Over Time')
plt.legend()
plt.show()

The code provided in sections 4.1, 4.2, and 4.3 can be written in a single Python file. Each section represents a part of the project, but they are designed to work together as a cohesive program.

Here’s how you can structure the file: 4.1 (Initializing the Depth Camera): This part sets up the camera and captures the depth frames. 4.2 (Processing Depth Data to Track Chest Movement): This part continues from the camera setup and processes the depth data to detect breathing patterns. 4.3 (Analyzing and Visualizing Breathing Patterns): This part can be executed after the data collection loop to analyze and visualize the captured breathing data.

4.4 Combined Code

import pyrealsense2 as rs
import numpy as np
import cv2
import time
import matplotlib.pyplot as plt

# Initializing the Depth Camera
pipeline = rs.pipeline()
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
pipeline.start(config)

# Processing Depth Data to Track Chest Movement
ROI_TOP_LEFT = (200, 150)
ROI_BOTTOM_RIGHT = (440, 300)
previous_avg_depth = None
breath_data = []

def calculate_average_depth(depth_image, roi_top_left, roi_bottom_right):
    roi = depth_image[roi_top_left[1]:roi_bottom_right[1], roi_top_left[0]:roi_bottom_right[0]]
    avg_depth = np.mean(roi)
    return avg_depth

try:
    start_time = time.time()

    while True:
        frames = pipeline.wait_for_frames()
        depth_frame = frames.get_depth_frame()
        if not depth_frame:
            continue

        depth_image = np.asanyarray(depth_frame.get_data())

        avg_depth = calculate_average_depth(depth_image, ROI_TOP_LEFT, ROI_BOTTOM_RIGHT)

        if previous_avg_depth is not None:
            depth_change = previous_avg_depth - avg_depth
            breath_data.append((time.time() - start_time, depth_change))

            if depth_change > 0:
                print("Breath In")
            elif depth_change < 0:
                print("Breath Out")

        previous_avg_depth = avg_depth

        cv2.rectangle(depth_image, ROI_TOP_LEFT, ROI_BOTTOM_RIGHT, (255, 0, 0), 2)
        cv2.imshow('Depth Image', depth_image)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

finally:
    pipeline.stop()
    cv2.destroyAllWindows()

# Analyzing and Visualizing Breathing Patterns
times, depth_changes = zip(*breath_data)

plt.figure(figsize=(10, 5))
plt.plot(times, depth_changes, label='Chest Movement')
plt.xlabel('Time (s)')
plt.ylabel('Depth Change (mm)')
plt.title('Breathing Pattern Over Time')
plt.legend()
plt.show()

5. Project Workflow

  • Camera Setup: Mount the camera at an angle where it captures the chest area of the person whose breathing you want to monitor.
  • ROI Definition: Define a region of interest (ROI) on the chest area where the camera will focus on detecting movement.
  • Data Collection: Start the system and capture depth data over time.
  • Breath Detection: Use the depth changes in the ROI to detect inhaling and exhaling motions.
  • Analysis: Record the data and analyze it to detect breathing patterns.
  • Visualization: Plot the data for visual analysis of the breathing rate and pattern.

6. Applications and Extensions

  • Real-Time Alerts: Extend the system to send alerts if irregular breathing is detected.
  • Integration with IoT: Connect the system to an IoT platform for remote monitoring.
  • Machine Learning: Train a model to classify different types of breathing patterns or detect anomalies.

This project provides a basic framework for tracking breathing patterns using a depth camera. You can expand it further based on your specific requirements, such as adding more sophisticated data processing, integrating with a database, or enhancing the visualization and user interface.


메타데이터
post_id
b41dd8775466
slug
health-monitoring-system-to-track-breathing-patterns-using-intel-realsense-d435i-depth-camera-b41dd8775466
url
https://medium.com/@wlspasan/health-monitoring-system-to-track-breathing-patterns-using-intel-realsense-d435i-depth-camera-b41dd8775466
canonical_url
https://medium.com/@wlspasan/health-monitoring-system-to-track-breathing-patterns-using-intel-realsense-d435i-depth-camera-b41dd8775466
author_url
https://medium.com/@wlspasan
status
ok
fetched_at
2026-07-21 09:12:41