-
Notifications
You must be signed in to change notification settings - Fork 1
/
Draw_lane
32 lines (25 loc) · 1.59 KB
/
Draw_lane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def draw_lane(img, left_line, right_line, lane_color=(255, 0,255), road_color=(50, 255,50)):
""" draw lane lines & current driving space """
window_img = np.zeros_like(img)
window_margin = left_line.window_margin
left_plotx, right_plotx = left_line.allx, right_line.allx
ploty = left_line.ally
# Generate a polygon to illustrate the search window area
# And recast the x and y points into usable format for cv2.fillPoly()
left_pts_l = np.array([np.transpose(np.vstack([left_plotx - window_margin/5, ploty]))])
left_pts_r = np.array([np.flipud(np.transpose(np.vstack([left_plotx + window_margin/5, ploty])))])
left_pts = np.hstack((left_pts_l, left_pts_r))
right_pts_l = np.array([np.transpose(np.vstack([right_plotx - window_margin/5, ploty]))])
right_pts_r = np.array([np.flipud(np.transpose(np.vstack([right_plotx + window_margin/5, ploty])))])
right_pts = np.hstack((right_pts_l, right_pts_r))
# Draw the lane onto the warped blank image
cv2.fillPoly(window_img, np.int_([left_pts]), lane_color)
cv2.fillPoly(window_img, np.int_([right_pts]), lane_color)
# Recast the x and y points into usable format for cv2.fillPoly()
pts_left = np.array([np.transpose(np.vstack([left_plotx+window_margin/5, ploty]))])
pts_right = np.array([np.flipud(np.transpose(np.vstack([right_plotx-window_margin/5, ploty])))])
pts = np.hstack((pts_left, pts_right))
# Draw the lane onto the warped blank image
cv2.fillPoly(window_img, np.int_([pts]), road_color)
result = cv2.addWeighted(img, 1, window_img, 0.3, 0)
return result, window_img