Overview :
● This project implements real-time lane and vehicle detection using the YOLOv8 model and OpenCV.
● It processes video frames to detect lanes using edge detection and Hough transform while simultaneously detecting vehicles and estimating their distance using YOLOv8.
Features :
● Lane detection using edge detection and Hough Line Transform.
● Vehicle detection using YOLOv8.
● Distance estimation of detected vehicles.
● Processes a video file and saves the output with detected lanes and vehicles.
Driver Requirement :
● Ensure you have the following dependencies installed:
● pip install opencv-python numpy ultralytics ( or ) pip install -r req.txt
● YOLOv8 weights file: yolov8n.pt
● Input video file: vdo.mp4
Installation & Setup :
● Clone the repository or copy the script.
● Install the required dependencies.
● Place the required files in the specified directory.
● Run the script: python lane_vehicle_detection.py
Configuration :
The following parameters can be adjusted based on camera calibration and input data:
● KNOWN_WIDTH: Approximate width of a car in meters.
● FOCAL_LENGTH: Estimated focal length of the camera.
● VEHICLE_CLASSES: List of vehicle classes to detect.
How It Works :
1. Lane Detection
● Converts the frame to grayscale.
● Applies Gaussian blur.
● Uses Canny edge detection.
● Masks the region of interest.
● Detects lanes using the Hough Line Transform.
2. Vehicle Detection & Distance Estimation
● Uses YOLOv8 for real-time vehicle detection.
● Estimates distance using the formula: Distance= (Known Width × Focal Length) / Bounding Box Width
● Annotates frames with bounding boxes and distance labels.
3. Video Processing
● Read the input video frame by frame.
● Processes each frame and writes to an output file.
● Displays real-time detection with an option to quit (q).
Output :
● The processed video with lane and vehicle detection is saved as output.avi.
● Detected vehicles are annotated with their class, confidence score, and estimated distance.
Project Files :
● Script file:
lane_vehicle_detection.py
● Model File:
yolov8n.pt file
● Requirements File:
req.txt
Running the Real-Time Detection :
● To start real-time detection, execute: python lane_vehicle_detection.py
● This will open a live camera feed and display the detected lanes and vehicles in real-time. Press
'q' to exit.
*** You want to update the file path According to your files ***