def main(): from glob import glob from camera_calibration import CameraCalibration from thresholding import threshold from transform import PerspectiveTransform # Fixed image dimensions height = 720 width = 1280 # Prepare camera calibration print("Calibrating camera") calibration = CameraCalibration.default() # Prepare perspective transform transform = PerspectiveTransform.default(height, width) images = glob('test_images/straight*') + glob('test_images/test*') for fname in images: print("Processing", fname) # Run pipeline img = cv2.imread(fname) img = calibration.undistort(img) img, _ = threshold(img) # img = cv2.morphologyEx(img, cv2.MORPH_CLOSE, (5,5)) img = transform.transform(img) # Find lines using sliding windows left_lane, right_lane = find_lines_with_sliding_windows(img) # Plot sliding windows plot_sliding_windows(img, left_lane, right_lane) # combined_binary, color_binary = threshold(img, stack=True) # # f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(32, 9)) # ax1.set_title('Stacked thresholds', fontsize=20) # ax1.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) # # ax2.set_title('Result', fontsize=20) # ax2.imshow(combined_binary, cmap='gray') plt.savefig('output_images/sliding_windows_' + fname.split('/')[-1])
def main(): # # Fixed image dimensions height = 720 width = 1280 transform = PerspectiveTransform.default(height, width) from camera_calibration import CameraCalibration calibration = CameraCalibration.default() images = glob('test_images/straight*') + glob('test_images/test*') for fname in images: print("Processing", fname) image = cv2.cvtColor(cv2.imread(fname), cv2.COLOR_BGR2RGB) image = calibration.undistort(image) polygonned = cv2.polylines(np.copy(image), [np.int32(transform.src)], False, color=255, thickness=1) transformed = transform.transform(np.copy(polygonned)) inversed = transform.invert().transform(np.copy(transformed)) f, (ax1, ax2, ax3, ax4) = plt.subplots(1, 4, figsize=(32, 9)) ax1.set_title('Original', fontsize=20) ax1.imshow(image) ax2.set_title('Area of interest', fontsize=20) ax2.imshow(polygonned) ax3.set_title('Transformed', fontsize=20) ax3.imshow(transformed) ax4.set_title('Transformed inversed', fontsize=20) ax4.imshow(inversed) plt.savefig('output_images/transform_' + fname.split('/')[-1])
def main(): # Fixed image dimensions height = 720 width = 1280 # Prepare camera calibration print("Calibrating camera") calibration = CameraCalibration.default() transform = PerspectiveTransform.default(height, width) images = glob('test_images/straight*') + glob('test_images/test*') for fname in images: print("Processing", fname) org_image = cv2.imread(fname) if org_image.shape != (height, width, 3): print("skipping image", fname, "invalid dimensions", org_image.shape) continue # Run the pipeline on a copy of the image undistorted = calibration.undistort(np.copy(org_image)) transformed = transform.transform(undistorted) warped_binary, _ = threshold(transformed, stack=False) # combined, _ = threshold(undistorted, stack=False) # warped_binary = transform.transform(combined) lane = Lane() lane.update(warped_binary) final = lane.overlay(org_image, draw_lines=False, fill_lane=True, transform=transform.invert()) final = lane.overlay_text(final) final = cv2.polylines(final, [np.int32(transform.src)], color=[255, 0, 0], isClosed=False) cv2.imwrite('output_images/lane_{}'.format(fname.split('/')[-1]), final) final = lane.overlay(np.dstack((warped_binary, warped_binary, warped_binary)) * 255, draw_lines=True, fill_lane=False) cv2.imwrite('output_images/lane_warped_{}'.format(fname.split('/')[-1]), final)
def create_camera_calibration(): return CameraCalibration.default()