This project implements a lane detection system using OpenCV to process images and videos for identifying lane markings. By transforming the camera's view and applying advanced image processing techniques, the system accurately detects lanes. It also offers multiple visualizations, including standard lane detection, bird's-eye view, and a sliding window view, making it a versatile tool for autonomous driving research.
The standard lane detection view displays the detected lane markings, direction arrows indicating the lane's curvature, the vehicle's center offset, and the calculated curve radius for accurate lane tracking.
short_video_complete.mp4
The bird's-eye view provides a top-down perspective of the road, highlighting the lane lines for better visualization of the lane's structure.
short_video_birds_eye.mp4
The sliding window view shows the detection process, using windows that track the lane markings along the road, ensuring consistent lane detection throughout the image.
short_video_sliding_window.mp4
- Python: Used as the primary programming language for implementing the lane detection algorithm.
- OpenCV: For image and video processing, including perspective transformation and lane detection.
- NumPy: To perform matrix operations for transformations and measurements.
- Matplotlib: For visualizing intermediate steps and final output.
- MoviePy: To handle video processing, including reading and writing video files.
- Docopt: For command-line argument parsing.
- Image/Video Capture
- In this step, frames are captured from a video stream (e.g., a dashboard camera) or single images are loaded for processing. Each frame or image serves as the input to the lane detection algorithm.
- Perspective Transformation
- This step involves transforming the camera's point of view into a bird’s-eye view. It allows you to see the road from a top-down perspective, making it easier to detect and analyze lane lines.
- Thresholding
- Here, the image is filtered to isolate the most important features, such as lane lines. Using techniques like color thresholding or gradient thresholding, unnecessary parts of the image are filtered out to highlight the lane region.
- Detecting Lanes
- Lane detection is carried out using the sliding window method and Canny edge detection. Canny edge detection helps identify the edges within the image, which are typically the lane boundaries. The sliding window technique is then used to detect and follow these lines along the lanes, ensuring accurate lane marking detection even when the road curves.
- Calculating Measurements
- After detecting the lanes, measurements such as the lane's curvature radius, the direction of the curve (left or right), and the vehicle’s offset from the center of the lane are calculated. These metrics help understand the road structure and assist in vehicle alignment.
main.py
: Entry point of the lane detection system.Thresholding.py
: Contains code for image thresholding to identify lane lines.PerspectiveTransformation.py
: Code for transforming the image to a bird's eye view.LaneLines.py
: Contains code for detecting and visualizing the lane lines.input_images/
: Contains sample input images for the program.input_videos/
: Contains sample input videos for the program.output_images/
: Stores output images processed by the program.output_videos/
: Stores output videos processed by the program.
- Clone the repository:
git clone https://github.com/BilalM04/autonomous-lane-detection.git
- Navigate to the project directory:
cd autonomous-lane-detection
- Install dependencies:
pip install -r requirements.txt
Run the application through the command line:
python main.py [--video | --image] [--all] INPUT_PATH
--video
: Process a video file.--image
: Process an image file.--all
: Output all results (lane detection, sliding window, and bird's eye view).
- Process a video with all visualizations:
python main.py --video --all ./input_videos/short_video.mp4
- Process an image with all visualizations:
python main.py --image --all ./input_images/straight_lines1.jpg
The resulting outputs are available in the output_images/
and output_videos/
directories.