The goals / steps of this project are the following:
- Make a pipeline that finds lane lines on the road
- Reflect on your work in a written report
The pipeline consisted of the following steps:
- Convert an image to grayscale using custom weights
- Apply gaussian blur filter
- Invoke Canny edge detection algorithm
- Apply region of interest filter
- Apply Hough transformation
- Calculate lanes directions from Hough segments
- Draw lanes using averager on the original image
I used custom channel weights while mixing channels to create grayscale image. The main reason to use custom weights - increase contrast of lanes on challenge video. The idea as simple as overweight light colors of lanes keeping surface color mostly untouched. As a result of overflow lanes become black on gray or light gray surface, hopefully this will give big enough gradients for Canny edge detection algorithm. Bellow result of standard and custom grayscale transformation.
Using custom weights and just integer overflow to increase contrast looks naïve and too simple. This may lead to unstable work of the pipeline in different conditions eg. different light sources, night time, tunnels, different road surfaces, different lane colors.
The main vector of improvements in this area - find suitable contrast enhancement algorithm which will work stable enough in wide range of light conditions.
One of downsides of grayscale conversion algorithm - it may introduce high gradients in unexpected spots. In order to minimize negative effect gaussian blur filter could be used.
The pipeline sets kernel to 7.
The kernel is too big, which may lead to lower gradients (and as a result to missed edges) in some spots.
Together with changing grayscale algorithm it's better to test the pipeline with lower kernel value.
The pipeline uses aggressive parameters for canny edges detection. Proposed grayscale conversion algorithm allows to do so. One of the reasons behind this - attempt to avoid edges produced by shadows.
Fragment of detection using standard grayscale transformation
Detection using custom grayscale transformation
Parameters of the pipeline:
- Low threshold - 120
- high threshold - 350
The pipeline uses following ROI shape.
There is an obvious advantage of such a narrow RoI - more edges which doesn't belong to lanes filtered out. On other hand there are plenty of disadvantages.
Narrow RoI is not that good choice since it:
- sensitive to camera position in the car - RoI is symmetric so camera should be mounted at the middle of the vehicle.
- sensitive to camera parameters (such as focal distance) - the same RoI could not be reused for a different camera
- sensitive to the position on the road - changing lanes or even driving not along to the center of the lane could lead to unstable detection
- suitable for highway-style roads - cross roads, turns, uphills and downhills may not be handled well using given RoI
The most important improvement (together with contrast enhancement algorithm) could be changing RoI shape. It could be either asymmetric wide region without blind zone in the middle, or even more complex polygon (two trapezoids with different angles?).
The pipeline uses complex algorithm to convert segments found by Hough transformation into lane lines.
- Invoke Hough transformation
- Filter out irrelevant segments
- For each side
- Calculate mean slope
- Find segment with slope closest to mean value
- Take middle point of the segment
- Find highest (in term of vertical axis) segment
- Evaluate appropriate x-coordinate using point from 3 and slope from 1
- Evaluate lane position on the bottom of image using point from 5 and slope from 1
Straight line sometimes not that good approximation for road lane lines.
In some cases detection could be not perfect, it may lead to "jumping" lane on the video stream. To avoid such behavior and provide smooth lane tracking the averager (not the best name actually) was introduced.
The main idea of the component - to track current position and instead of applying the whole delta at once go step by step to the target value.
The averager works well if only some frames have lane detection problems. In case if long video fragment has some anomaly it will take more time to recover even when detection perfectly done.