Skip to main content

YOLO-based ROI detection system with RTMP streaming

Project description

YOLO Zone Detector

A comprehensive Python package for person detection and tracking in danger zones using YOLO models, with real-time RTSP streaming capabilities.

✨ Features

  • Person Detection: Advanced YOLO-based person detection and tracking
  • Danger Zone Management: Create and manage danger zones with file-based or interactive mouse-based setup
  • Real-time Tracking: Track people entering/leaving danger zones with time-based warnings
  • RTSP Streaming: Stream detection results via RTSP protocol
  • Flexible Configuration: Support for various video sources (webcam, video files)
  • Warning System: Configurable time-based warnings for safety monitoring

🚀 Installation

Using Poetry (Recommended)

# Clone the repository
git clone https://git.aipower.vn/minhcq/zone-detect.git
cd zone-detector

# Install with Poetry
poetry install

# Activate virtual environment
poetry shell

Using pip

# Install from PyPI (when published)
pip install yolo-zone-detector

# Or install from source
pip install git+https://git.aipower.vn/minhcq/zone-detect.git

📦 Dependencies

  • Python 3.8+
  • OpenCV (cv2)
  • Ultralytics YOLO
  • PyTorch
  • NumPy
  • CVZone

🎯 Quick Start

Command Line Interface

# Interactive mode
yolo-zone-detector --interactive

# Direct usage with webcam
yolo-zone-detector --video 0 --zone-mode 1 --streaming

# Use video file with mouse-based zone creation
yolo-zone-detector --video path/to/video.mp4 --zone-mode 2

# Full configuration
yolo-zone-detector \
  --video path/to/video.mp4 \
  --model yolo11s.pt \
  --zone-mode 1 \
  --warning-time 15.0 \
  --streaming \
  --rtsp-url rtsp://localhost:8554/live

Python API

from zone_detector import YOLODetectionStreamer

# Create detector instance
detector = YOLODetectionStreamer(
    video_path='path/to/video.mp4',
    model_path='yolo11n.pt',
    zone_mode=1,  # 1: file-based, 2: mouse-based
    warning_time=10.0,
    enable_streaming=True,
    rtsp_url='rtsp://localhost:8554/live'
)

# Start detection
capture_thread, stream_thread = detector.start_streaming()

# Wait for completion
capture_thread.join()
if stream_thread:
    stream_thread.join()

# Clean up
detector.stop_streaming()

Using Individual Components

from yolo_zone_detector import ZoneManager, YOLOModel, PersonTracker

# Zone management
zone_manager = ZoneManager(zone_mode=1)

# YOLO model
yolo_model = YOLOModel(model_path='yolo11n.pt')

# Person tracking
tracker = PersonTracker(warning_time=10.0)

# Process frame
results = yolo_model.detect_and_track(frame)
people_in_zone = tracker.update_tracking(results, zone_manager, current_time)

🎮 Controls

Keyboard Controls (During Detection)

  • q: Quit application
  • r: Reset tracking data
  • d: Force detection update
  • s: Start detection (after zone setup)

Mouse Controls (Zone Mode 2)

  • Left Click: Add point to zone
  • Right Click: Complete zone creation
  • c: Clear selected points
  • n: Complete zone creation
  • z: Toggle zone creation mode

⚙️ Configuration

Zone Modes

  1. File-based (Mode 1): Load zones from danger_zones.json
  2. Mouse-based (Mode 2): Create zones interactively with mouse

Zone File Format (danger_zones.json)

{
    "default_zone": [
        [115,217],
        [868,227],
        [881,385],
        [122,395],
        [55,296]
    ],
    "custom_zones": [
        [
            [115,217],
            [868,227],
            [881,385],
            [122,395],
            [55,296]
        ]
    ]
}

RTSP Streaming

The package supports RTSP streaming via FFmpeg. Make sure FFmpeg is installed:

# Ubuntu/Debian
sudo apt install ffmpeg

# macOS
brew install ffmpeg

# Windows
# Download from https://ffmpeg.org/download.html

📊 Performance

  • Detection Interval: Configurable (default: 0.5s)
  • Supported Models: All YOLO11 variants (n, s, m, l, x)
  • Video Sources: Webcam, video files, network streams
  • Output: Real-time annotation with RTSP streaming

🔧 Development

Setup Development Environment

Building Package

# Build package
poetry build

# Publish to PyPI
poetry publish

Installation

pip install zone-detector

yolo-roi --video my_video.mp4 --zone-mode 1

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zone_detection-0.1.1.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zone_detection-0.1.1-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file zone_detection-0.1.1.tar.gz.

File metadata

  • Download URL: zone_detection-0.1.1.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Windows/10

File hashes

Hashes for zone_detection-0.1.1.tar.gz
Algorithm Hash digest
SHA256 10facae5a5c72f5e433953cf990201dff92d2ec94c5aba2262be10566ac38d27
MD5 1c5d41cfb89326c45c9a23e243dde621
BLAKE2b-256 4e561db941edbc3b6b985011de435fc5250ac2e1e902f1f6492dca3d1004ffdf

See more details on using hashes here.

File details

Details for the file zone_detection-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: zone_detection-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Windows/10

File hashes

Hashes for zone_detection-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d54a8ea4939c60991abd694e209090c624e5dd0eb62d9fe08df48547b8e44f41
MD5 7cc8bc612b9d8dfb9b6abee25c9e610a
BLAKE2b-256 033389395ddd0415ff72d26a739b6e6ebf66d3ee8538ddd4d4f957899dcfba94

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page