-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdraw_detected_lanes.py
36 lines (31 loc) · 1.14 KB
/
draw_detected_lanes.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
import numpy as np
import cv2
from scipy.misc import imresize
from moviepy.editor import VideoFileClip
from IPython.display import HTML
from keras.models import load_model
class Lanes():
def __init__(self):
self.recent_fit = []
self.avg_fit = []
def road_lines(image):
small_img = imresize(image, (80, 160, 3))
small_img = np.array(small_img)
small_img = small_img[None,:,:,:]
prediction = model.predict(small_img)[0] * 255
lanes.recent_fit.append(prediction)
if len(lanes.recent_fit) > 5:
lanes.recent_fit = lanes.recent_fit[1:]
lanes.avg_fit = np.mean(np.array([i for i in lanes.recent_fit]), axis = 0)
blanks = np.zeros_like(lanes.avg_fit).astype(np.uint8)
lane_drawn = np.dstack((blanks, lanes.avg_fit, blanks))
lane_image = imresize(lane_drawn, (720, 1280, 3))
result = cv2.addWeighted(image, 1, lane_image, 1, 0)
return result
if __name__ == '__main__':
model = load_model('full_CNN_model.h5')
lanes = Lanes()
vid_output = 'vid.mp4'
clip1 = VideoFileClip("video.mp4")
vid_clip = clip1.fl_image(road_lines)
vid_clip.write_videofile(vid_output, audio=False)