Self-Driving Cars: Finding Lanes

Nitin Vaish
3 min readFeb 1, 2017

One of the first steps to driving is to know where to drive. When we begin driving and over subsequent years, we take the basic concept of driving between lanes for granted. Self driving cars need to learn that. So, how do we find lanes?

It starts off with processing a 2D image (Figure 1), where each pixel will have a value on the RGB scale from o-255, with darkest being 0. The task is relatively easier when the lane markers are white, and the image can be processed, using matplotlib library, to set the RGB values below a threshold to 0 and hence only highlighting white pixels(Figure 2).

Figure 1

Once these pixels are highlighted, we’ve to identify the region of interest where the vehicle can drive. Using NumPy, a python package for multi-dimensional array and matrix analysis, a triangular region of interest in defined in Figure 3, with lanes markers in the region highlighted. Note that several of these packages are built-in Anaconda, which also comes handy with data analysis.

The above situation becomes trickier when the lanes markers are of different color or the visibility is poor, where simple RGB threshold will likely not work. To overcome this, a technique called Canny edge detection, which analyzes the gradient or change in pixels to detect boundaries, is employed. Various computer vision libraries are built-in OpenCV package. Figure 4 is the output of Canny edge detection package on the original image after converting to grayscale.

Figure 4

The last remaining piece is zeroing down on lanes. This is accomplished by converting the image into Hough space. Essentially, think of this as converting a line (y = mx + b) in the image space to a dot in Hough space (with parameters m and b). Intersection of several lines in the Hough space will be a line in the image space. Various parameters, e.g. minimum number of intersecting lines, max gap between pixels etc can be adjusted to filter out non-lane edges that were detected. Figure 5 is an output subsequent to this transform when applied to region of interest.

Figure 5

This is a high-level overview to give you an intuition of various steps involved for a simple task that we humans take for granted while driving! If you’re interested, I’d encourage you to check out the course.

--

--

Nitin Vaish

Decarbonization Solutions at Scale: Commercialization | Products | Investments