import glob import cv2 import os import pickle from lane_detector import LaneDetector from frame_composer import FrameComposer from undistorter import Undistorter with open('./undistorter.pkl', 'rb') as f: undistorter = pickle.load(f) ld = LaneDetector(undistorter) files = glob.glob('./data/test_images/*.jpg') # files = ['./data/test_images/test1.jpg'] for file in files: image = cv2.imread(file) frame_with_lane_filled, frame_with_lines_n_windows_2d, thresholded_frame, radius_of_curvature = ld.run(image) base = os.path.basename(file) fc = FrameComposer(image) fc.add_mask_over_base(frame_with_lane_filled) fc.add_upper_bar((frame_with_lines_n_windows_2d, thresholded_frame)) fc.add_text('Raduis of curvature: {}'.format(radius_of_curvature)) cv2.imwrite('./data/test_images_output/{}_{}.jpg'.format(os.path.splitext(base)[0], 'lane_detected'), fc.get_frame())
file_index = result["filename"][-5] cv2.imwrite("OUTPUT/calibration/1-corners%s.jpg" % file_index, result["img"]) cv2.imwrite("OUTPUT/calibration/2-corners-undistorted-%s.jpg" % file_index, camera.undistort(result["img"])) # HSV color mask color_mask = ( ((20, 50, 75), (110, 255, 255)), # yellow lines ((0, 0, 220), (255, 255, 255)) # white lines ) # Process images for filename in glob.glob("raw_images/*.jpg"): detector = LaneDetector(camera, perspective, color_mask) detector.run(cv2.imread(filename), "OUTPUT/test%s" % filename[-5]) # Process video cap = cv2.VideoCapture("road.mp4") out = cv2.VideoWriter("road_processed.avi", cv2.VideoWriter_fourcc(*'XVID'), 25, (1280, 720)) detector = LaneDetector(camera, perspective, color_mask) i = 0 while cap.isOpened(): ret, frame = cap.read() if not ret: break i += 1