Skip to content

An autonomous lane detection system leveraging OpenCV to process images and videos, accurately identifying lanes and providing key visualizations.

Notifications You must be signed in to change notification settings

BilalM04/autonomous-lane-detection

Repository files navigation

Autonomous Lane Detection

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.

Standard Lane Detection

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

Bird's Eye View

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

Sliding Window View

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

Technologies Used

  • 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.

Lane Detection Workflow

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

Project Structure

  • 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.

Installation

  1. Clone the repository:
    git clone https://github.com/BilalM04/autonomous-lane-detection.git
  2. Navigate to the project directory:
    cd autonomous-lane-detection
  3. Install dependencies:
    pip install -r requirements.txt

Usage

Run the application through the command line:

python main.py [--video | --image] [--all] INPUT_PATH

Options

  • --video: Process a video file.
  • --image: Process an image file.
  • --all: Output all results (lane detection, sliding window, and bird's eye view).

Example commands

  1. Process a video with all visualizations:
    python main.py --video --all ./input_videos/short_video.mp4
  2. Process an image with all visualizations:
    python main.py --image --all ./input_images/straight_lines1.jpg

Results

The resulting outputs are available in the output_images/ and output_videos/ directories.

About

An autonomous lane detection system leveraging OpenCV to process images and videos, accurately identifying lanes and providing key visualizations.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages