Lane Detection with Computer Vision

Amey Karmarkar
3 min readOct 2, 2020

--

Lane detection is one of the important component of Autonomous Driving Vehicle Systems (ADAS). With the aim to detect the lane on the road, I have developed a pipeline using Python and OpenCV.

Pipeline consists of following steps —

  1. Grayscale conversion
  2. Gaussian Smoothing
  3. Canny Edge Detection
  4. ROI Selection
  5. Hough Transform
  6. Line Extrapolation
Original Image

Grayscale Conversion

Convert RGB image to Grayscale which will help in color masking

Grayscale Converted Image

Gaussian Smoothing

Gaussian smoothing is performed to reduce the noise in image.

Gaussian Blur Image

Canny Edge Detection

Canny Edge Detection is performed to find the edges in the image. Two important parameters to consider in canny edge detection are — Lower threshold and High threshold. The algorithm will first detect strong edge (strong gradient) pixels above the high threshold, and reject pixels below the low threshold. Next, pixels with values between the low threshold and high threshold will be included as long as they are connected to strong edges

Edge Detected Image

ROI Selection

ROI (Region of interest) selection is performed to remove the unwanted edges.

Edge Detection after ROI

Hough Transform

Hough Transform is used to detect the lines from the edge detected image. Few of the important parameters to consider are

rho — distance resolution of grid in Hough space

theta — Angular resolution of grid in Hough space

threshold — minimum number of votes or intersections to consider that point as part of line

min_line_length — minimum length of line in pixels to consider it in output

max_line_gap — maximum gap between segments to be considered as single line

It is important to tweak this parameters to get the better results.

Line Extrapolation

Hough Transform provides multiple line segments but to draw a continuous left lane and right lane, I have used the line extrapolation method where I have taken average of slope of line segments for left and right lane respectively.

Detected Lane
Final Output
Video Output

Code of this implementation is available at — https://github.com/ameykarmarkar/Computer-Vision-Lane-Detection

--

--