logo
0
0
WeChat Login

Safe AI Room Occupancy Monitoring System

A safety-focused room occupancy monitoring system for industrial environments, leveraging Ultralytics YOLOv8 for person detection.

Repository: https://cnb.cool/MindDockAI/yolo-room-occupancy-safety

IMPORTANT

SAFETY CRITICAL WARNING: This software is a PROTOTYPE. In a real industrial setting, this must be redundant to physical interlocks (e.g., light curtains, pressure mats). Do NOT rely solely on Computer Vision for life-safety applications unless using certified hardware/software compliant with ISO 13849 / IEC 61508.

Features

  • Person Detection: Uses YOLOv8 to detect humans.
  • Line Crossing Counting: Tracks entries and exits through defined virtual doors. (You must physically cross the line to be counted).
  • Global Safety State: Maintains a global count of people in the room.
  • Robot Control Logic:
    • STOP: If count > 0 OR System Error.
    • START: Only if count == 0.
  • Fail-Safe:
    • Watchdog for camera frame drops.
    • Auto-reconnection logic for cameras.
    • Defaults to "Occupied" (Stop) on any failure.

System Requirements

  • OS: Windows 11, macOS, or Linux.
  • Python: 3.8 or higher.
  • Hardware: Webcam or RTSP Camera (one per door).

Installation

1. Clone the Repository

git clone https://cnb.cool/MindDockAI/yolo-room-occupancy-safety.git cd yolo-room-occupancy-safety

2. Set up Python Environment

macOS / Linux

Open a terminal and run:

# Create a virtual environment python3 -m venv venv # Activate the environment source venv/bin/activate # Install dependencies pip install -r requirements.txt

Windows

Open PowerShell or Command Prompt and run:

# Create a virtual environment python -m venv venv # Activate the environment (PowerShell) .\venv\Scripts\Activate.ps1 # OR for Command Prompt: # venv\Scripts\activate.bat # Install dependencies pip install -r requirements.txt

Note for macOS Users: If you encounter errors related to ultralytics or torch, ensure you have the latest version of pip: pip install --upgrade pip.

Configuration

Edit config.yaml to match your physical setup.

cameras: - id: 0 source: "0" # Webcam ID (0) or RTSP URL ("rtsp://...") line_start: [100, 200] line_end: [500, 200] # Define the virtual door line (x, y) direction_in: "down" # Detection direction logic (currently vector based)
  • source: Use 0, 1 for USB webcams, or an RTSP stream URL.
  • system.debug_mode: Set to true to see the video feed with detection overlays.

Usage

Running the System

Ensure your virtual environment is activated, then run:

python -m src.main

The system will start monitoring. Press q to exit if debug window is open.

Mock/Simulation Mode

You can test the logic without a camera by generating a mock video.

  1. Generate the video:
    python tests/mock_generator.py # Creates mock_video.mp4
  2. Update Config: In config.yaml, set source: "mock_video.mp4".
  3. Run Main:
    python -m src.main

Safety & Reliability Notes

  • Camera Watchdog: If a camera stops sending frames for >0.5s (configurable), the system enters Error State.
  • Negative Count: If the count accidentally goes below 0 (logic error), it resets to 0 but logs a warning. In a strict safety version, this should trigger a Stop.
  • Redundancy: Verify the logical "In/Out" direction matches your physical camera mounting orientation.

Troubleshooting

  • YOLO Tracking Error (no module named lap): The project uses lapx instead of lap. Ensure you run pip install -r requirements.txt.
  • Camera Timeout: If using a webcam that takes time to initialize, you may see immediate "Camera TIMEOUT" errors. Increase system.max_missing_frames in config.yaml (e.g., to 60 or higher).

License

MIT (or specify your license)

About

A safety-focused room occupancy monitoring system for industrial environments, leveraging [Ultralytics YOLOv8](https://github.com/ultralytics/ultralytics) for person detection.

Language
Python100%