Skip to content

mtgsoftworks/UAV-Advanced-Tracking-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿš UAV Advanced Tracking System

Python Version YOLO OpenCV PyTorch License

UAV Advanced Tracking System is an advanced computer vision system developed for UAV/drone detection and tracking. It performs real-time UAV tracking using YOLOv8s deep learning model and OpenCV tracker algorithms. The system is equipped with optimized parameters based on academic research findings and a PID control system.

๐ŸŽฏ Features

๐Ÿ”ฅ Dual Tracking Approach

  • YOLO-only Tracking: YOLO detection + Kalman Filter in every frame
  • OpenCV Tracker: 7 different classical tracking algorithms (CSRT, KCF, MOSSE, MIL, BOOSTING, MEDIANFLOW, TLD)

๐Ÿง  AI Integration

  • YOLOv8s custom model support
  • GPU/CPU automatic optimization
  • Confidence threshold academic optimization (20% main, 15% tracking)
  • NMS IOU threshold adjustable (0.4 optimized)

๐ŸŽฎ Advanced Control System

  • PID Controller dynamic gain adjustment
  • Kalman Filter smooth tracking
  • ROI scanning system (4 region optimized)
  • Adaptive threshold (far/near distance)

๐Ÿ“Š Performance Monitoring

  • Real-time FPS indicator
  • Confidence tracking and statistics
  • Bbox history and smooth filtering
  • Detection timeout control

๐Ÿš€ Quick Start

๐Ÿ“‹ Requirements

  • Python 3.10+
  • Windows 10/11 (tested)
  • CUDA compatible GPU (optional, for acceleration)
  • Webcam or video file

โšก Installation

  1. Clone the repository:
git clone https://github.com/yourusername/uav-tracking-system.git
cd uav-tracking-system
  1. Create virtual environment:
python -m venv uav_env
# For Windows:
.\uav_env\Scripts\activate
# For Linux/Mac:
source uav_env/bin/activate
  1. Install dependencies:
pip install --upgrade pip
pip install opencv-python torch ultralytics numpy opencv-contrib-python
  1. Alternative - Installation with requirements:
pip install -r requirements.txt

๐ŸŽฌ Usage

YOLO-only Tracker (Recommended):

python uav_tracking_yolo.py

OpenCV Tracker Version:

python uav_tracking_opencv_trackers.py

๐Ÿ“น Video Configuration

Place your video files in the Scenes/ folder:

UAV/
โ”œโ”€โ”€ Scenes/
โ”‚   โ”œโ”€โ”€ scene1.mp4
โ”‚   โ”œโ”€โ”€ scene2.mp4
โ”‚   โ””โ”€โ”€ ...
โ”œโ”€โ”€ best.pt (YOLO model)
โ””โ”€โ”€ ...

๐Ÿ”ง Technical Details

๐ŸŽฏ Optimal Threshold Values

Threshold values optimized according to academic research findings:

Parameter Value Description
Main Detection Confidence 20% Optimal for initial detection
Tracking Confidence 15% More sensitive during tracking
IOU Threshold (NMS) 0.4 Non-Maximum Suppression
Minimum Bbox Size 2.5% frame For small UAVs
Target Area 1.5% frame PID control reference

๐Ÿ“Š ROI Scanning System

Systematic scanning with 4 large ROI regions:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  ROI 1  โ”‚  ROI 2  โ”‚
โ”‚ (Top-L) โ”‚ (Top-R) โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  ROI 3  โ”‚  ROI 4  โ”‚
โ”‚ (Bot-L) โ”‚ (Bot-R) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  • ROI Size: 640x360 (with overlap)
  • Scanning Speed: 12 frame/ROI
  • Total Scan: ~1.6 seconds/cycle

๐ŸŽฎ PID Control System

Adaptive PID gains based on distance:

Distance Kp Ki Kd Kf Usage
Far 300 35 80 1480 Distant targets
Close 200 50 120 1480 Near targets

๐Ÿง  Kalman Filter Configuration

8-state Kalman filter (x, y, w, h, vx, vy, vw, vh):

  • Process Noise: 5e-3 (low noise, stable tracking)
  • Measurement Noise: 1e-1 (YOLO detection reliability)
  • Prediction Model: Constant velocity

๐Ÿ“ˆ OpenCV Tracker Comparison

Based on LearnOpenCV reference, tracker performance:

Tracker Accuracy Speed UAV Suitability Recommended
CSRT โญโญโญโญโญ โญโญ ๐ŸŸข Best โœ… Precise tracking
KCF โญโญโญโญ โญโญโญโญ ๐ŸŸข Good โœ… General purpose
MOSSE โญโญโญ โญโญโญโญโญ ๐ŸŸก Speed focused โšก Real-time
MIL โญโญโญ โญโญโญ ๐ŸŸก Basic ๐Ÿ“š Simple
TLD โญโญโญโญ โญโญ ๐ŸŸก Occlusion ๐Ÿ” Experimental
MEDIANFLOW โญโญโญ โญโญโญ ๐Ÿ”ด Not suitable โŒ Slow motion only
BOOSTING โญโญ โญโญ ๐Ÿ”ด Not recommended โŒ Outdated

๐ŸŽจ User Interface

๐ŸŽฏ YOLO-only Version

  • Green box: UAV tracking active
  • Yellow area: Target region
  • Red line: Center-target connection
  • Control panel: PID values real-time
  • ROI indicator: Scanning mode

๐ŸŽฎ Control Keys

  • Q: Exit
  • R: Tracking reset
  • S: Screenshot (YOLO version only)

๐Ÿ“Š Information Indicators

  • FPS: Real-time performance
  • Confidence: Detection confidence
  • PID Values: Aileron, Elevator, Throttle
  • Target Area: Current/target area ratio

๐Ÿ”ฌ Academic Optimizations

๐Ÿ“š Confidence Threshold Research

Literature review results:

  • YOLOv8 Default: 0.4 (too high, UAVs missed)
  • LMWP-YOLO Study: 0.25 recommended
  • UAV Detection Papers: 0.2-0.25 range optimal
  • This Project: 0.2 (main), 0.15 (tracking)

๐ŸŽฏ ROI Optimization

  • Old: 6 small ROI (3x2 grid) โ†’ Confusing scanning
  • New: 4 large ROI (2x2 grid) โ†’ 40% more efficient
  • Overlap: 100px โ†’ Edge case handling
  • Frame/ROI: 15 โ†’ 12 frame (20% speedup)

๐Ÿš€ Performance Benchmarks

๐Ÿ’ป Test System

  • CPU: Intel i7 series
  • GPU: CUDA compatible (optional)
  • RAM: 8GB+ recommended
  • Video: 1280x720 @ 30fps

๐Ÿ“Š Performance Results

Mode FPS CPU Usage GPU Usage Detection Rate
YOLO-only 15-25 60-80% 40-60% 95%+
CSRT Tracker 20-30 40-60% 20-40% 85%+
MOSSE Tracker 35-45 30-50% 15-30% 80%+

๐ŸŽฏ Detection Accuracy

On test videos:

  • Confidence Range: 31% - 94%
  • Average Confidence: 76%
  • Detection Success: 92%
  • False Positive: <5%
  • Tracking Loss: <8%

๐Ÿ—‚๏ธ Project Structure

UAV/
โ”œโ”€โ”€ ๐Ÿ“ Scenes/              # Video files
โ”‚   โ”œโ”€โ”€ scene1.mp4
โ”‚   โ””โ”€โ”€ scene2.mp4
โ”œโ”€โ”€ ๐Ÿ“ uav_env/             # Python virtual environment
โ”œโ”€โ”€ ๐Ÿ uav_tracking_yolo.py   # Main YOLO tracker
โ”œโ”€โ”€ ๐Ÿ uav_tracking_opencv_trackers.py  # OpenCV trackers
โ”œโ”€โ”€ ๐Ÿ test_trackers.py       # Tracker test script
โ”œโ”€โ”€ ๐Ÿง  best.pt               # YOLOv8s custom model
โ”œโ”€โ”€ ๐Ÿ“‹ requirements.txt      # Python dependencies
โ””โ”€โ”€ ๐Ÿ“– README.md             # This file

๐Ÿ”ง Advanced Configuration

โš™๏ธ YOLO Model Settings

# Model parameters
CONF_THRESHOLD = 0.2        # Main detection
TRACK_CONF_THRESHOLD = 0.15 # Tracking detection
IOU_THRESHOLD = 0.4         # NMS threshold
MAX_DET = 100              # Maximum detections

๐ŸŽฎ PID Tuning

# Far distance gains
gains_far = {
    'Kp': 300,    # Proportional gain
    'Ki': 35,     # Integral gain  
    'Kd': 80,     # Derivative gain
    'Kf': 1480    # Feedforward
}

# Near distance gains
gains_close = {
    'Kp': 200,    # Softer control
    'Ki': 50,     # Higher integral
    'Kd': 120,    # Higher derivative
    'Kf': 1480    # Constant feedforward
}

๐Ÿ” ROI Customization

# ROI size settings
roi_width = frame_width // 2   # 640px default
roi_height = frame_height // 2 # 360px default
overlap = 100                  # Overlap pixels
ROI_SCAN_FRAMES = 12          # Frame/ROI

๐Ÿ›  Troubleshooting

โŒ Common Errors

  1. "CUDA out of memory"

    # Switch to CPU mode
    device = "cpu"
  2. "TrackerCSRT_create not found"

    # Install OpenCV-contrib
    pip install opencv-contrib-python
  3. "Video file cannot be opened"

    # Check video path
    VIDEO_PATH = "Scenes/scene1.mp4"

๐Ÿ”ง Performance Tuning

  1. GPU Memory Optimization:

    torch.cuda.empty_cache()  # Clear memory
  2. Frame Rate Optimization:

    cv2.waitKey(1)  # Reduce display delay
  3. Detection Frequency:

    # Detect every 2nd frame
    if frame_count % 2 == 0:
        detect()

๐Ÿค Contributing

  1. Fork it
  2. Create feature branch: git checkout -b amazing-feature
  3. Commit changes: git commit -m 'Add amazing feature'
  4. Push to branch: git push origin amazing-feature
  5. Open Pull Request

๐Ÿ›  Development Setup

# Development dependencies
pip install pytest black flake8 mypy

๐Ÿงช Testing

# Tracker tests
python test_trackers.py

# Unit tests (future)
pytest tests/

๐Ÿ“š References and Resources

๐Ÿ“– Academic Sources

๐Ÿ”— Technical Documentation

๐ŸŽฏ Confidence Threshold Research

  • LMWP-YOLO: Optimized threshold studies
  • UAV Detection Papers: 0.2-0.25 optimal range
  • Real-world deployment findings

๐Ÿ“ž Contact

๐Ÿ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.

๐Ÿ† Acknowledgments

  • YOLOv8 team
  • OpenCV community
  • LearnOpenCV for educational materials
  • PyTorch framework
  • Academic research contributions

๐Ÿ‘จโ€๐Ÿ’ป Author

Mesut Taha Gรผven - Lead Developer & Researcher

Specialized in computer vision, UAV systems, and real-time tracking algorithms. Passionate about combining academic research with practical applications.

๐Ÿ“Š Changelog

v2.0 (Latest)

  • โœ… Dual tracking system implementation
  • โœ… Academic optimization integration
  • โœ… OpenCV tracker fallback mechanism
  • โœ… Improved ROI scanning
  • โœ… Enhanced PID control

v1.0 (Initial)

  • โœ… Basic YOLO detection
  • โœ… Simple tracking implementation
  • โœ… ROI scanning prototype

โญ Don't forget to star the project if you liked it!

๐Ÿš UAV Advanced Tracking System - Where AI Meets Precision

About

Real-time UAV detection & tracking system powered by YOLOv8, OpenCV, and PID control

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages