Skip to content

Lane Detection system using OpenCV implemented in python, using Canny edge detect and Hough transform algorithms

Notifications You must be signed in to change notification settings

Ashwin-Rajesh/LaneDetection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This project implements a simple lane detection system using Canny edge detect and Hough transform algorithms.

Implemented using OpenCV Python API

Processing steps

  1. Edge detection
  2. Line detection
  3. Detecting boundaries

Overview

  • First, the image feed is resized to a standard resolution, here, it is 1200 by 700.
  • Image is converted to grayscale since the edge detection algorithm works in grayscale.
  • Gaussian blur filter is applied to remove noise
  • The canny edge detect algorithm is applied
  • A mask is applied so that only relevant area is analysed
  • Lines are deteted using Hough transform
  • Lines are filtered, and grouped into left and right boundary, and boundary lines are detected

Edge detection

  • 'Canny' algorithm is used to detect edges. It is an improvement on the sobel filter edge detection algorithm.
  • The sobel filter convolves a kernel that looks like the one below, over the image

sobel filter image sobel filter image

  • The first kernel selects vertical edges, because it is symmetrical about horizontal axis.
  • Similarly, the second kernel selects horizontal edges
  • Sobel filter otputs is not sharp and has a LOT of noise! This is solved by the canny algorithm
  • Canny algorithm output is really sharp! This is achieved by a technique called non-max suppression.
  • It also has very low noise. This is done by a clever type of thresholding.
  • For understanding this in detail, theres a lot of great material! Check out computerphile!

Line detection

  • Line detection uses an algorithm called Hough transform
  • For each point in an image, there are a lot of lines that can pass thorough that point. If we represent all these lines using some parameters, say slope and y-intercept, then the parameters of all lines that could pass through a point will form a line in the "Hough space".
  • When the parmaters for possible lines for 2 points intersect at some point in the space of line parameters, Those line parameters will form the line that passes through the 2 points.
  • For imperfect lines, those parameters will not intersect for all points, but at some location, they will all pass close. This will be detected as a line.
  • I know its hard to understand this completely from such shallow an explanation, please check out some videos, they will make it easier to understand!

Line filtering and grouping

  • Now that we have our detected lines with us, we need to figure out the lane boundaries from them. First, lines that are too steep or too flat are removed.
  • Then, lines with a positive slope are categorized as part of the right boundary and those with negative slope as that of left boundary
  • Remeber that in images, the top-left corner is (0,0) and increases down and towards the right. This could be awkward, especially when talking about slope, for those of us used to normal cartesian space coordinates
  • Now, the average of slope and intercept for these lines that we categorized before are computed, and these are taken as boundary ofthe lane!

Now, just take all that and do some math and overlay that on top of the original image! Thats it!

Exponentially weighted average

  • To make the line detections more smooth, a technique called exponnectial moving average is used.
  • A value called the moving sum is what represents the final lines. It is obtained by adding previous moving average to the current line detection.
  • The result is that sudden changes in the lane detections do not affect the result tooo much. As a side-effect, there is a slight delay when the lane detections move during turning and such.
  • The coefficients while adding previous sum and current detection need to be tweaked to get a balance between fast response and good stabilisation.

Result

  • Here are some videos of the result: Nighttime driving

About

Lane Detection system using OpenCV implemented in python, using Canny edge detect and Hough transform algorithms

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages