forked from ndrplz/self-driving-car
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (50 loc) · 2.24 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
import matplotlib.pyplot as plt
import cv2
import os
from os.path import join, basename
from collections import deque
from lane_detection import color_frame_pipeline
if __name__ == '__main__':
resize_h, resize_w = 540, 960
verbose = True
if verbose:
plt.ion()
figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()
# test on images
test_images_dir = join('data', 'test_images')
test_images = [join(test_images_dir, name) for name in os.listdir(test_images_dir)]
for test_img in test_images:
print('Processing image: {}'.format(test_img))
out_path = join('out', 'images', basename(test_img))
in_image = cv2.cvtColor(cv2.imread(test_img, cv2.IMREAD_COLOR), cv2.COLOR_BGR2RGB)
out_image = color_frame_pipeline([in_image], solid_lines=True)
cv2.imwrite(out_path, cv2.cvtColor(out_image, cv2.COLOR_RGB2BGR))
if verbose:
plt.imshow(out_image)
plt.waitforbuttonpress()
plt.close('all')
# test on videos
test_videos_dir = join('data', 'test_videos')
test_videos = [join(test_videos_dir, name) for name in os.listdir(test_videos_dir)]
for test_video in test_videos:
print('Processing video: {}'.format(test_video))
cap = cv2.VideoCapture(test_video)
out = cv2.VideoWriter(join('out', 'videos', basename(test_video)),
fourcc=cv2.VideoWriter_fourcc(*'DIVX'),
fps=20.0, frameSize=(resize_w, resize_h))
frame_buffer = deque(maxlen=10)
while cap.isOpened():
ret, color_frame = cap.read()
if ret:
color_frame = cv2.cvtColor(color_frame, cv2.COLOR_BGR2RGB)
color_frame = cv2.resize(color_frame, (resize_w, resize_h))
frame_buffer.append(color_frame)
blend_frame = color_frame_pipeline(frames=frame_buffer, solid_lines=True, temporal_smoothing=True)
out.write(cv2.cvtColor(blend_frame, cv2.COLOR_RGB2BGR))
cv2.imshow('blend', cv2.cvtColor(blend_frame, cv2.COLOR_RGB2BGR)), cv2.waitKey(1)
else:
break
cap.release()
out.release()
cv2.destroyAllWindows()