-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
82 lines (64 loc) · 2.61 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
74
75
76
77
78
79
80
81
82
from moviepy.video.io.VideoFileClip import VideoFileClip
from scipy import misc
from src.advancedLaneDetector import AdvancedLaneDetector
from src.undistorter import Undistorter
from src.postprocessor import Postprocessor
from src.thresholdtypes import ThresholdTypes
# Set camera name to 'default', 'UM', or 'blackfly' for calibration and warping
camera = 'default'
# camera = 'UM'
# camera = 'blackfly'
# camera = 'blackfly_reduced'
advancedLaneDetector = AdvancedLaneDetector(camera)
undistorter = Undistorter(camera)
postprocessor = Postprocessor()
threshold_types = list(map(int, ThresholdTypes))
def main():
video = 'data/project_video'
# video = 'data/UM'
# video = 'data/sample14'
# video = 'data/sample14_reduced'
white_output = '{}_done.mp4'.format(video)
clip1 = VideoFileClip('{}.mp4'.format(video))
clip1 = clip1.subclip(0, 0.025)
white_clip = clip1.fl_image(process_image)
white_clip.write_videofile(white_output, audio=False)
def process_image(img):
# Image Undistortion
undistorted_img = undistorter.undistort(img)
misc.imsave('output_images/undistorted.jpg', undistorted_img)
# Run Lane Detection Algorithms
results = run_lane_detection_algs(undistorted_img)
# Post Processing
postprocessed_image = postprocessor.postprocess(undistorted_img, results)
misc.imsave('output_images/final.jpg', postprocessed_image)
return postprocessed_image
def run_lane_detection_algs(undistorted_img):
# Define acceptable confidence
acceptable_conf = 0.8
left_thresh = None
right_thresh = None
# Define number of images to be merged
# num_merged_images = [1, 10]
num_merged_images = [1]
results = []
for num_merged in num_merged_images:
for threshold in threshold_types:
# Run advanced lane detection
results.append(advancedLaneDetector.detect_lanes(
undistorted_img, threshold, num_merged))
# Check if left and right confidence are acceptable
if results[-1].left_conf >= acceptable_conf:
left_thresh = threshold
if results[-1].right_conf >= acceptable_conf:
right_thresh = threshold
# Reorder threshold priority for more efficient run on next frame
if left_thresh is not None and right_thresh is not None:
threshold_types.remove(left_thresh)
threshold_types.insert(0, left_thresh)
threshold_types.remove(right_thresh)
threshold_types.insert(0, right_thresh)
return results
return results
if __name__ == '__main__':
main()