Book Image

Hands-On Vision and Behavior for Self-Driving Cars

By : Luca Venturi, Krishtof Korda
Book Image

Hands-On Vision and Behavior for Self-Driving Cars

By: Luca Venturi, Krishtof Korda

Overview of this book

The visual perception capabilities of a self-driving car are powered by computer vision. The work relating to self-driving cars can be broadly classified into three components - robotics, computer vision, and machine learning. This book provides existing computer vision engineers and developers with the unique opportunity to be associated with this booming field. You will learn about computer vision, deep learning, and depth perception applied to driverless cars. The book provides a structured and thorough introduction, as making a real self-driving car is a huge cross-functional effort. As you progress, you will cover relevant cases with working code, before going on to understand how to use OpenCV, TensorFlow and Keras to analyze video streaming from car cameras. Later, you will learn how to interpret and make the most of lidars (light detection and ranging) to identify obstacles and localize your position. You’ll even be able to tackle core challenges in self-driving cars such as finding lanes, detecting pedestrian and crossing lights, performing semantic segmentation, and writing a PID controller. By the end of this book, you’ll be equipped with the skills you need to write code for a self-driving car running in a driverless car simulator, and be able to tackle various challenges faced by autonomous car engineers.
Table of Contents (17 chapters)
1
Section 1: OpenCV and Sensors and Signals
5
Section 2: Improving How the Self-Driving Car Works with Deep Learning and Neural Networks
12
Section 3: Mapping and Controls

Finding the lanes using histograms

How could we understand, more or less, where the lanes are? Visually, for a human, the answer is simple: the lane is a long line. But what about a computer?

If we talk about vertical lines, one way could be to count the pixels that are white, on a certain column. But if we check the image with a turn, that might not work. However, if we reduce our attention to the bottom part of the image, the lines are a bit more vertical:

Figure 3.25 – Lane with a turn, after the threshold, the bottom part

Figure 3.25 – Lane with a turn, after the threshold, the bottom part

We can now count the pixels by column:

partial_img = img[img.shape[0] // 2:, :]  # Select the bottom part
hist = np.sum(partial_img, axis=0)  # axis 0: columns direction

To save the histogram as a graph, in a file, we can use Matplotlib:

import matplotlib.pyplot as plt

plt.plot(hist)plt.savefig(filename)plt.clf()

We obtain the following result:

Figure 3.26 – Left: histogram of a straight lane, right: histogram of a lane with a turn

Figure 3.26...