我正在教授有关如何驾驶赛车的机器学习模型。因此,我从道路边缘检测开始。问题在于边缘不是很清晰。
我尝试了HoughLines算法,虽然做得很好,但还不够。
这是我的代码:
def process_img(original_image):
# convert to gray
processed_img = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY)
# edge detection
processed_img = cv2.Canny(processed_img, threshold1=200, threshold2=300)
# Blur the view
processed_img = cv2.GaussianBlur(processed_img, (5,5), 0)
vertices = np.array([[100, 500], [10,300], [300,200], [500,200], [800,300], [800,500]], np.int32)
# remove unecessary elements from the view
processed_img = roi(processed_img, [vertices])
# draw road edges using Hough algorithm
lines = cv2.HoughLinesP(processed_img, 1, np.pi/180, 180, 20, 15)
draw_lines(processed_img, lines)
return processed_img
PS:游戏是第一人称视角,因此视野是从车内观看的。