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 applicationr: Reset tracking datad: Force detection updates: Start detection (after zone setup)
Mouse Controls (Zone Mode 2)
- Left Click: Add point to zone
- Right Click: Complete zone creation
c: Clear selected pointsn: Complete zone creationz: Toggle zone creation mode
⚙️ Configuration
Zone Modes
- File-based (Mode 1): Load zones from
danger_zones.json - 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
Metadata
Release files for zone_detection 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zone_detection-0.1.1.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zone_detection-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.8 kB
Release files / zone_detection-0.1.1.tar.gz
| Download URL | zone_detection-0.1.1.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10facae5a5c72f5e433953cf990201dff92d2ec94c5aba2262be10566ac38d27
|
|
BLAKE2b-256 checksum How to use checksums |
4e561db941edbc3b6b985011de435fc5250ac2e1e902f1f6492dca3d1004ffdf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Windows/10
|
Release files / zone_detection-0.1.1-py3-none-any.whl
| Download URL | zone_detection-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d54a8ea4939c60991abd694e209090c624e5dd0eb62d9fe08df48547b8e44f41
|
|
BLAKE2b-256 checksum How to use checksums |
033389395ddd0415ff72d26a739b6e6ebf66d3ee8538ddd4d4f957899dcfba94
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.5 Windows/10
|