You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A real-time Advanced Driver Assistance System built with a hybrid Rust + Python architecture. Performance-critical perception (lane detection, object tracking, traffic-light classification, ONNX inference) runs in compiled Rust via PyO3 bindings, while the application layer orchestrates everything in Python with OpenCV and Ultralytics YOLO.
Features
Subsystem
Implementation
Description
Lane Detection
Rust (lane_detect.rs)
Canny edge detection → Hough transform with trapezoidal ROI masking. Returns left/right lane lines.
Lane Management
Rust (lane_manager.rs)
Exponential smoothing of lane lines across frames, left/right grouping, and ego-lane object filtering. Supports highway and two-way road modes.
Object Detection
Python (Ultralytics YOLOv8)
GPU-accelerated vehicle detection (cars, motorcycles, buses, trucks) via PyTorch CUDA.
Object Tracking & TTC
Rust (object_proc.rs)
Centroid-based frame-to-frame tracker. Estimates distance (pinhole camera model), relative speed, and time-to-collision (TTC).
Traffic Light Detection
Rust (traffic_light.rs)
HSV colour analysis on the upper third of each frame. Classifies as RED / YELLOW / GREEN / NONE.
Traffic Sign Recognition
Rust (lib.rs — AdasBrain)
Loads a custom ONNX model, runs YOLOv8-style inference entirely in Rust via the ort runtime, with NMS post-processing.
Multi-threaded Camera
Python (main.py)
Dedicated background thread for video decoding and resizing, keeping the main inference loop unblocked.
Real-time HUD
Python (main.py)
OpenCV overlay showing lane lines, bounding boxes colour-coded by threat level, distance/speed labels, traffic light status, sign labels, and FPS counter.
NVIDIA GPU + CUDA toolkit (recommended for real-time performance)
An ONNX-compatible runtime (bundled via the ort crate)
Setup
# 1. Clone the repository
git clone <repo-url>&&cd adas_pilot
# 2. Create a Python virtual environment
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows# 3. Install Python dependencies
pip install maturin opencv-python numpy torch ultralytics onnxruntime-gpu
# 4. Build the Rust extension (compiles & installs into the active venv)
maturin develop --release
# 5. Place a test video# Put your dashcam video at assets/videos/test_vid.mp4# 6. Runcd app
python main.py
Usage
cd app
python main.py
Controls
Press q to quit.
Configuration (main.py)
Variable
Default
Description
IS_TWO_WAY_ROAD
False
Set to True for two-way roads (changes lane-filtering logic and left-lane colour).
AI_SKIP_FRAMES
3
Run heavy AI (YOLO + ONNX) every N-th frame to maintain FPS.
SIGN_CLASSES
{52: "STOP"}
Map ONNX class IDs to human-readable sign names.
HUD Colour Coding
Colour
Meaning
🟢 Green box
Tracked vehicle — safe distance
🟡 Yellow box
Caution — vehicle within 25 m or TTC < 5 s
🔴 Red box
Danger — ego-lane vehicle with TTC < 2.5 s
🟣 Magenta box
Detected traffic sign
Training a Custom Traffic Sign Model
# 1. Prepare a YOLO-format dataset under assets/datasets/ with a data.yaml# 2. Traincd app
python tools/train_signs.py
# 3. Export best weights to ONNX
python tools/export_model.py
# 4. Move the .onnx file to models/traffic_signs.onnx
Key Dependencies
Rust (Cargo.toml)
Crate
Purpose
pyo3 0.21
Python ↔ Rust bindings
ort 2.0.0-rc.9 (CUDA)
ONNX Runtime inference
numpy 0.21
NumPy ↔ ndarray interop
image 0.25
Image decoding & resizing
imageproc 0.25
Canny edge detection, Hough transform
ndarray 0.15
N-dimensional array operations
Python
Package
Purpose
opencv-python
Video I/O, image processing, HUD rendering
numpy
Array operations
torch
PyTorch backend for Ultralytics YOLO
ultralytics
YOLOv8 object detection
onnxruntime
ONNX provider verification
maturin
Build system for the Rust extension
Troubleshooting
Problem
Fix
ModuleNotFoundError: adas_pilot
Run maturin develop --release inside the project root with your venv active.
Video not found
Ensure assets/videos/test_vid.mp4 exists. The app falls back to test_video.mp4 in app/.
YOLO fails to load on GPU
Verify CUDA is installed: python -c "import torch; print(torch.cuda.is_available())".
ONNX model not found
Ensure models/traffic_signs.onnx exists. Train one with tools/train_signs.py or supply your own.
Low FPS
Increase AI_SKIP_FRAMES, use a smaller YOLO model, or ensure GPU acceleration is active.
License
See repository root for license information.
About
An ADAS system having only the software part aiming for guidance rather than control