-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
52 lines (43 loc) · 1.64 KB
/
main.py
File metadata and controls
52 lines (43 loc) · 1.64 KB
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
import numpy as np
import matplotlib.image as mpimg
import cv2
from IPython.display import HTML, Video
from moviepy.editor import VideoFileClip
from CameraCalibration import CameraCalibration
from Thresholding import *
from PerspectiveTransformation import *
from LaneLines import *
class FindLaneLines:
def __init__(self):
""" Init Application"""
self.calibration = CameraCalibration('camera_cal', 9, 6)
self.thresholding = Thresholding()
self.transform = PerspectiveTransformation()
self.lanelines = LaneLines()
# Processes the image through the pipeline
def forward(self, img):
out_img = np.copy(img)
img = self.calibration.undistort(img)
img = self.transform.forward(img)
img = self.thresholding.forward(img)
img = self.lanelines.forward(img)
img = self.transform.backward(img)
out_img = cv2.addWeighted(out_img, 1, img, 0.6, 0)
out_img = self.lanelines.plot(out_img)
return out_img
# Process an image and save the output
def process_image(self, input_path, output_path):
img = mpimg.imread(input_path)
out_img = self.forward(img)
mpimg.imsave(output_path, out_img)
# Process a video and save the output
def process_video(self, input_path, output_path):
clip = VideoFileClip(input_path)
out_clip = clip.fl_image(self.forward)
out_clip.write_videofile(output_path, audio=False)
def main():
""" Main function to process a video. """
findLaneLines = FindLaneLines()
findLaneLines.process_video("project_video.mp4","output.mp4")
if __name__ == "__main__":
main()