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:
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: