A vision-based autonomous vehicle perception pipeline built using Python, OpenCV, and PyTorch / YOLOv8.
This system processes camera video inputs to detect driving-relevant objects (vehicles, pedestrians), track them across frames, estimate their lateral and depth distances, track lane lines, and compute safe control actions (such as emergency braking and lane departure warnings).
- Object Detection: Leverages YOLOv8 (with a lightweight fallback traditional CV detector using OpenCV color segmentation) to recognize cars, trucks, buses, motorcycles, and pedestrians.
- Multi-Object Tracking: Centroid and Intersection-over-Union (IoU) tracker that assigns stable tracking IDs across frames and handles short-term occlusions.
-
Monocular Depth / Distance Estimation: Computes physical obstacle distance (in meters) from camera height projection equations (
$d = \frac{f \cdot H}{h}$ ) and provides a model hook for MiDaS-based depth maps. - Lane Line Detection: Performs perspective warp (bird's-eye view), HLS color thresholding, sliding window searching, second-order polynomial curve fitting, and offset tracking.
-
Safety Decision Layer: Estimates closing speed relative velocities, evaluates Time-to-Collision (TTC) to trigger emergency braking (
BRAKE), and checks vehicle deviation to trigger Lane Departure Warnings (WARN). - Telemetry HUD Overlay: Draws real-time vehicle tracks, lane overlays, and a dashboard panel summarizing system alerts.
-
Release Scheduler: Integrates a staging compiler (
commit_scheduler.py) to commit and push the codebase in daily increments of approximately 15% to maintain a gradual commit log.
Autonomous Perception System/
├── requirements.txt # Package dependencies
├── .gitignore # Files to ignore in Git
├── config.py # Configurations & camera matrix calibration
├── generate_synthetic_video.py # Generates synthetic test video data
├── main.py # Main orchestrator pipeline
├── commit_scheduler.py # Daily commit scheduler
├── commit_state.json # Scheduler tracking file
├── README.md # Project documentation
├── src/ # Pipeline implementation package
│ ├── __init__.py
│ ├── utils.py # HUD and dashboard overlay tools
│ ├── video_stream.py # Video capture & generator wrapper
│ ├── detector.py # YOLOv8 / OpenCV color detector
│ ├── tracker.py # Centroid & IoU track manager
│ ├── lane_detector.py # OpenCV perspective lane solver
│ ├── depth_estimator.py # Geometric & MiDaS depth estimator
│ └── decision_logic.py # TTC and lateral position decision layer
└── tests/ # Unit tests package
├── __init__.py
└── test_pipeline.py # Math and logic verification tests
- Create a local virtual environment:
python3 -m venv venv source venv/bin/activate - Install project dependencies:
pip install -r requirements.txt
If you don't have CARLA or recorded driving videos, generate a realistic synthetic driving sequence (curving lanes, ahead braking vehicle, and crossing pedestrian):
python generate_synthetic_video.pyThis writes a sample video file to data/driving_sample.mp4.
Run the main orchestrator (automatically loads the synthetic video if no external source is supplied):
python main.pyPress q on the GUI window to exit.
- Run on a custom video file:
python main.py --video path/to/your_video.mp4
- Run in headless mode (saves the processed output video to
output/processed_drive.mp4without showing a display GUI):python main.py --no-view
- Enable Deep Learning Depth Mapping (uses PyTorch Hub to run the MiDaS monocular depth model):
python main.py --use-dl-depth
Run the unit test suite to verify math projection coordinate conversions, tracking associations, and collision warning logic:
python -m unittest tests/test_pipeline.py