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.
- YOLO-only Tracking: YOLO detection + Kalman Filter in every frame
- OpenCV Tracker: 7 different classical tracking algorithms (CSRT, KCF, MOSSE, MIL, BOOSTING, MEDIANFLOW, TLD)
- YOLOv8s custom model support
- GPU/CPU automatic optimization
- Confidence threshold academic optimization (20% main, 15% tracking)
- NMS IOU threshold adjustable (0.4 optimized)
- PID Controller dynamic gain adjustment
- Kalman Filter smooth tracking
- ROI scanning system (4 region optimized)
- Adaptive threshold (far/near distance)
- Real-time FPS indicator
- Confidence tracking and statistics
- Bbox history and smooth filtering
- Detection timeout control
- Python 3.10+
- Windows 10/11 (tested)
- CUDA compatible GPU (optional, for acceleration)
- Webcam or video file
- Clone the repository:
git clone https://github.com/yourusername/uav-tracking-system.git
cd uav-tracking-system- Create virtual environment:
python -m venv uav_env
# For Windows:
.\uav_env\Scripts\activate
# For Linux/Mac:
source uav_env/bin/activate- Install dependencies:
pip install --upgrade pip
pip install opencv-python torch ultralytics numpy opencv-contrib-python- Alternative - Installation with requirements:
pip install -r requirements.txtpython uav_tracking_yolo.pypython uav_tracking_opencv_trackers.pyPlace your video files in the Scenes/ folder:
UAV/
โโโ Scenes/
โ โโโ scene1.mp4
โ โโโ scene2.mp4
โ โโโ ...
โโโ best.pt (YOLO model)
โโโ ...
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 |
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
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 |
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
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 |
- Green box: UAV tracking active
- Yellow area: Target region
- Red line: Center-target connection
- Control panel: PID values real-time
- ROI indicator: Scanning mode
Q: ExitR: Tracking resetS: Screenshot (YOLO version only)
- FPS: Real-time performance
- Confidence: Detection confidence
- PID Values: Aileron, Elevator, Throttle
- Target Area: Current/target area ratio
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)
- 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)
- CPU: Intel i7 series
- GPU: CUDA compatible (optional)
- RAM: 8GB+ recommended
- Video: 1280x720 @ 30fps
| 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%+ |
On test videos:
- Confidence Range: 31% - 94%
- Average Confidence: 76%
- Detection Success: 92%
- False Positive: <5%
- Tracking Loss: <8%
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
# 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# 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 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-
"CUDA out of memory"
# Switch to CPU mode device = "cpu"
-
"TrackerCSRT_create not found"
# Install OpenCV-contrib pip install opencv-contrib-python -
"Video file cannot be opened"
# Check video path VIDEO_PATH = "Scenes/scene1.mp4"
-
GPU Memory Optimization:
torch.cuda.empty_cache() # Clear memory
-
Frame Rate Optimization:
cv2.waitKey(1) # Reduce display delay
-
Detection Frequency:
# Detect every 2nd frame if frame_count % 2 == 0: detect()
- Fork it
- Create feature branch:
git checkout -b amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin amazing-feature - Open Pull Request
# Development dependencies
pip install pytest black flake8 mypy# Tracker tests
python test_trackers.py
# Unit tests (future)
pytest tests/- LearnOpenCV Object Tracking Guide
- YOLOv8 Official Documentation
- OpenCV Tracking Algorithms Documentation
- UAV Detection Research Papers
- LMWP-YOLO: Optimized threshold studies
- UAV Detection Papers: 0.2-0.25 optimal range
- Real-world deployment findings
- Email: your.email@domain.com
- GitHub: @yourusername
- LinkedIn: Your Profile
This project is licensed under the MIT License. See the LICENSE file for details.
- YOLOv8 team
- OpenCV community
- LearnOpenCV for educational materials
- PyTorch framework
- Academic research contributions
Mesut Taha Gรผven - Lead Developer & Researcher
- GitHub: @mtgsoftworks
- Email: mtg@duck.com
Specialized in computer vision, UAV systems, and real-time tracking algorithms. Passionate about combining academic research with practical applications.
- โ Dual tracking system implementation
- โ Academic optimization integration
- โ OpenCV tracker fallback mechanism
- โ Improved ROI scanning
- โ Enhanced PID control
- โ 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