In this section, we will detect road markings in a video. To do so, we will use OpenCV:
- First, import the required libraries:
In[1]: import cv2
In[2]: import numpy as np
In[3]: import matplotlib.pyplot as plt
- Define the make_coordinates function:
In[3]: def make_coordinates(image, line_parameters):
slope, intercept = line_parameters
y1 = image.shape[0]
y2 = int(y1*(3/5))
x1 = int((y1- intercept)/slope)
x2 = int((y2 - intercept)/slope)
return np.array([x1, y1, x2, y2])
- Define the average_slope_intercept function:
In[4]: def average_slope_intercept(image, lines):
left_fit = []
right_fit = []
for line in lines:
x1, y1, x2, y2 = line.reshape(4)
parameter = np.polyfit((x1, x2), (y1, y2), 1)
slope = parameter[0]
intercept = parameter[1]
if slope < 0:
left_fit.append((slope, intercept))
...