-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (58 loc) · 2.21 KB
/
main.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import cv2
import numpy as np
from lane_detection import detect_lane, detect_edges, region_of_interest, detect_line_segments, average_slope_intercept
from heading import *
import math
def display_lines(frame, lines, line_color=(0, 255, 0), line_width=2):
line_image = np.zeros_like(frame)
if lines is not None:
for line in lines:
for x1, y1, x2, y2 in line:
cv2.line(line_image, (x1, y1), (x2, y2), line_color, line_width)
line_image = cv2.addWeighted(frame, 0.8, line_image, 1, 1)
return line_image
def display_heading_line(frame, steering_angle, line_color=(0, 0, 255), line_width=5, ):
heading_image = np.zeros_like(frame)
height, width, _ = frame.shape
# figure out the heading line from steering angle
# heading line (x1,y1) is always center bottom of the screen
# (x2, y2) requires a bit of trigonometry
# Note: the steering angle of:
# 0-89 degree: turn left
# 90 degree: going straight
# 91-180 degree: turn right
steering_angle_radian = steering_angle / 180.0 * math.pi
x1 = int(width / 2)
y1 = height
x2 = int(x1 - height / 2 / math.tan(steering_angle_radian))
y2 = int(height / 2)
cv2.line(heading_image, (x1, y1), (x2, y2), line_color, line_width)
heading_image = cv2.addWeighted(frame, 0.8, heading_image, 1, 1)
return heading_image
# edges = detect_edges(frame)
# cv2.imshow("edges", edges)
# cv2.waitKey(0)
# cropped = region_of_interest(edges)
# cv2.imshow("edges", cropped)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
frame = cv2.imread('IMG_1051.png')
frame = cv2.resize(frame, (640, 480), interpolation = cv2.INTER_AREA)
"""
edges = detect_edges(frame)
cropped_edges = region_of_interest(edges)
line_segments = detect_line_segments(cropped_edges)
# print(line_segments)
print('here')
lane_lines = average_slope_intercept(frame, line_segments)
print(lane_lines)
cv2.imshow("heading", cropped_edges)
cv2.waitKey(0)
"""
lane_lines = detect_lane(frame)
print(len(lane_lines))
lane_lines_image = display_lines(frame, lane_lines)
heading_image = display_heading_line(frame, compute_steering_angle(frame, lane_lines))
cv2.imshow("lane lines", lane_lines_image)
cv2.imshow("heading", heading_image)
cv2.waitKey(0)