You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+242-3Lines changed: 242 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# **Lane Lines Detection Using Python and OpenCV**
2
-
In this project, I used Python and OpenCV to detect lane lines on the road. # I developed a processing pipeline that works on a series of individual images, and applied the result to a video stream.
2
+
In this project, I used Python and OpenCV to detect lane lines on the road. I developed a processing pipeline that works on a series of individual images, and applied the result to a video stream.
We need to detect edges in the images to be able to correctly detect lane lines.
88
+
The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images.
89
+
The Canny algorithm involves the following steps:
90
+
- Gray scaling the images: The Canny edge detection algorithm measures the intensity gradients of each pixel. So, we need to convert the images into gray scale in order to detect edges.
91
+
- Gaussian smoothing: Since all edge detection results are easily affected by image noise, it is essential to filter out the noise to prevent false detection caused by noise. To smooth the image, a Gaussian filter is applied to convolve with the image. This step will slightly smooth the image to reduce the effects of obvious noise on the edge detector.
92
+
- Find the intensity gradients of the image.
93
+
- Apply non-maximum suppression to get rid of spurious response to edge detection.
94
+
- Apply double threshold to determine potential edges.
95
+
- Track edge by hysteresis: Finalize the detection of edges by suppressing all the other edges that are weak and not connected to strong edges.
96
+
If an edge pixel’s gradient value is higher than the high threshold value, it is marked as a strong edge pixel. If an edge pixel’s gradient value is smaller than the high threshold value and larger than the low threshold value, it is marked as a weak edge pixel. If an edge pixel's value is smaller than the low threshold value, it will be suppressed. The two threshold values are empirically determined and their definition will depend on the content of a given input image.
97
+
98
+
### **4. Region of interest**
99
+
----
100
+
We're interested in the area facing the camera, where the lane lines are found. So, we'll apply region masking to cut out everything else.
101
+
102
+
```python
103
+
defregion_selection(image):
104
+
"""
105
+
Determine and cut the region of interest in the input image.
106
+
Parameters:
107
+
image: An np.array compatible with plt.imshow.
108
+
"""
109
+
mask = np.zeros_like(image)
110
+
#Defining a 3 channel or 1 channel color to fill the mask with depending on the input image
111
+
iflen(image.shape) >2:
112
+
channel_count = image.shape[2]
113
+
ignore_mask_color = (255,) * channel_count
114
+
else:
115
+
ignore_mask_color =255
116
+
#We could have used fixed numbers as the vertices of the polygon,
117
+
#but they will not be applicable to images with different dimesnions.
The Hough transform is a technique which can be used to isolate features of a particular shape within an image. I'll use it to detected the lane lines in `selected_region_images`.
132
+
133
+
```python
134
+
defhough_transform(image):
135
+
"""
136
+
Determine and cut the region of interest in the input image.
137
+
Parameters:
138
+
image: The output of a Canny transform.
139
+
"""
140
+
rho =1#Distance resolution of the accumulator in pixels.
141
+
theta = np.pi/180#Angle resolution of the accumulator in radians.
142
+
threshold =20#Only lines that are greater than threshold will be returned.
143
+
minLineLength =20#Line segments shorter than that are rejected.
144
+
maxLineGap =300#Maximum allowed gap between points on the same line to link them
### **6. Averaging and extrapolating the lane lines**
150
+
----
151
+
We have multiple lines detected for each lane line. We need to average all these lines and draw a single line for each lane line. We also need to extrapolate the lane lines to cover the full lane line length.
152
+
```python
153
+
defaverage_slope_intercept(lines):
154
+
"""
155
+
Find the slope and intercept of the left and right lanes of each image.
0 commit comments