Udacity无人驾驶课程—车道线识别

车道线识别

三通道图像,[0,0,0]是黑色,[256,256,256]为白色,从图片中筛选出白色车道线。

Process

此为测试图片,筛选出其中白色车道线,思路为确定阀值,阀值以下部分全部置为[0,0,0],即黑色,则阀值越高,越能筛选出图片中浅色的部分,当阀值足够高时,可只保留图片中白色的部分。测试图片,代码,测试结果如下:
Udacity无人驾驶课程—车道线识别_第1张图片

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

# Read in the image
image = mpimg.imread('test.jpg')

# Grab the x and y size and make a copy of the image
ysize = image.shape[0]
xsize = image.shape[1]
color_select = np.copy(image)

# Define color selection criteria
###### MODIFY THESE VARIABLES TO MAKE YOUR COLOR SELECTION
###注意,以下三行为阀值,可根据需要改变
red_threshold = 20
green_threshold = 20
blue_threshold = 220
######

rgb_threshold = [red_threshold, green_threshold, blue_threshold]

# Do a boolean or with the "|" character to identify
# pixels below the thresholds
thresholds = (image[:,:,0] < rgb_threshold[0]) \
            | (image[:,:,1] < rgb_threshold[1]) \
            | (image[:,:,2] < rgb_threshold[2])
color_select[thresholds] = [0,0,0]

# Display the image                 
plt.imshow(color_select)
plt.show()
# Uncomment the following code if you are running the code locally and wish to save the image
mpimg.imsave("test-after.png", color_select)

Udacity无人驾驶课程—车道线识别_第2张图片
好意希望与你一同成长。

你可能感兴趣的:(无人驾驶)