Implementation and results are in the Jupyter notebook.
Finding Lane Lines on the Road
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 detection algorithm consists of several step beginning from the original image to the drawing lane lines on the image. The steps are as follows:
-
Converting the image to grayscale
First step of the pipeline is to convert the image to grayscale so that the edge information can be attained. image1 Shows the result of conversion to grayscale.
-
Getting rid of glithces on the edges by blurring the image
The image is filtered before calculating the gradients in order to remove small glitches. To do this operation I used a kernel of size 5x5. image2 Shows the result of this operation. Edit after review: I decreased the gaussian kernel size to 3x3.
-
Edge detection and thresholding with Canny edge detector
The third step is to find the edges. A Canny edge detector is used for this operation. Lower threshold value is selected 50, and higher threshold is 130 for this operation. image3 demonstrates the result of Canny edge detection.
-
Masking the region or interest As the fourth step of the pipeline the edges in the regions that cannot belog to lane lines are eliminated. I used a region of interest in the images that can be lanes. image4 shows the region of interes selected in the image.
Applying this region of interest to edge image results in the edges shown in image5.
-
Finding the lane lines using Hough transform After finding lane lines I employed Hough transform on the edge image to find the lines. I picked the line thickness as 3 points and angle as 2 degrees. I picked the decision threshold to 100 points. Since the dashed lines have a large gap between consecutive lines, I used a large value (100) for max_line_gap parameter. And I used a small value for min_line_len parameter. image6 shows the result of the lines found with Hough transform.
-
Combining the lines with the image Finally, I combined the lane image with the original image as shown in image7.
I modified the draw_line() function in order to extend the lines to the limits of the region of interest (ROI). For each line that would be drawn I fit a line, which is denoted by y=m*x+n
. For this specific case where final y values are known, I fit a line x=y*m+n
. And found the m
and n
values from the x and y values of the lines. After that I extended the lines to the edge y values of the ROI. image8 shows the extended lines, and image9 shows the lines overlaid on the original image.
Another change I made in the function is for the challenge video. In the challenge video there are a lot of shadows and sudden changes on tarmac. To ignore these changes I put a limit to the angles of the lines that will be drawn. I did this by fitting a second line y=m*x+n
to the x and y values and discarded the values that fell in a certain range.
Edit after review:
I modified the draw_line() function to group the detected lines with similar slopes. After the lines are groupped similar lines a polygon that encapsulates the the lines are drawn. This way, a single line, per lane line, is drawn on image.
The obvious shortcoming of the current pipeline is that when there is curvature on the road. The reason for this is that we are searching for lines with Hough transform.
Another shortcoming is that shadows could be misinterpreted as lane lines on the road if the sun is bright enough. Also long vehicles can be interpreted easily lanes since they will have a large edge.
A possible improvement to the pipeline might be to separate the ROI into two parts in y-axis. With two ROI parts a better line fitting can be found. In addition to that, this solution would help us to estimate the curvature of the road. Another solution would be to use a circular Hough transform instead of a linear one. The resulting circle could be fit a second order polynomal, instead of first order.
I also neglected color information on the image, which is a very useful information. We know that lane lines are either white or yellow. Color filtering can be implemented to enhance the result and eliminate a lot of false positives.
Finally there is some shape information we did not employ here. We all know that lane lines are within a certain thickness range. This thickness information can be used too. Lines found with the Hough transform can be grouped together based on their distances in the x-dimension. With this grouping we can find the thicknesses of detected lines, and accept/reject some of them according to this criteria.
Edit after review I groupped the lines however I did not apply the thickness criterion.