根据像素的亮度来识别车
车道识别对于Computer vision 来说是一个相对简单的任务。原因是车道一般是白色或黄色 并且很容易和图片中其他的像素区别开来。
在RGB 三信道 的图片中, 白色有很高的R, G, B 的像素值。 所以我们就可以根据这个来threshold并且把低于threshold的像素给filter out 掉。 这里用Python来做演示:
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
image = mpimg.imread('test.jpg')
ysize = image.shape[0]
xsize = image.shape[1]
color_select = np.copy(image)
red_threshold = 230
green_threshold = 230
blue_threshold = 230
rgb_threshold = [red_threshold, green_threshold, blue_threshold]
thresholds = (image[:,:,0] < rgb_threshold[0]) \
| (image[:,:,1] < rgb_threshold[1]) \
| (image[:,:,2] < rgb_threshold[2])
color_select[thresholds] = [0,0,0]
plt.subplot(121)
plt.imshow(image)
plt.axis('off')
plt.subplot(122)
plt.imshow(color_select)
plt.axis('off')
plt.show()
得到的结果如下:
因为车道外的其他区域也有很多亮的区域, 我们可以手动来做一个mask 区域然后只threshold这块区域里面的部分:
left_bottom = [0, 539]
right_bottom = [900, 300]
apex = [400, 0]
fit_left = np.polyfit((left_bottom[0], apex[0]), (left_bottom[1], apex[1]), 1)
fit_right = np.polyfit((right_bottom[0], apex[0]), (right_bottom[1], apex[1]), 1)
fit_bottom = np.polyfit((left_bottom[0], right_bottom[0]), (left_bottom[1], right_bottom[1]), 1)
XX, YY = np.meshgrid(np.arange(0, xsize), np.arange(0, ysize))
region_thresholds = (YY > (XX*fit_left[0] + fit_left[1])) & \
(YY > (XX*fit_right[0] + fit_right[1])) & \
(YY < (XX*fit_bottom[0] + fit_bottom[1]))
region_select[region_thresholds] = [255, 0, 0]
plt.imshow(region_select)
最后可以把识别到的路线放回到原来的图片里面去:
这个方法翠然简单方便但是很不robust, 因为仅仅根据像素的亮度在很多时候会得到错误的结果(比如树荫下或者其他颜色的车道)并且我们事先要知道一个区域才能比较准确的得到结果。 下面, 会介绍更加可靠的方法来解决这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)