def main(): test_images = get_input_path("test_images").glob("*.jpg") from pathlib import Path lane_detector = LaneDetector() for i, test_image_path in enumerate(test_images): test_image_path = get_input_path("test_images").joinpath("test1.jpg") image = mpimg.imread(str(test_image_path)) plt.figure plt.imshow(image) warp_matrix, img = transform_image(image) left_fitx, right_fitx, ploty, out_img = lane_detector.get_lanes( img, draw=True) # left_fitx, right_fitx, ploty = lane_detector.get_polynominals(out_img, leftx, lefty, rightx, righty) fig = plt.figure() fig.suptitle("Polylines") plt.imshow(out_img) plt.imsave( str(get_output_folder_path().joinpath( f"{test_image_path.stem}_lanes.jpg")), image) plt.show() break
def main(): """ Main function it an example function """ test_images = get_input_path("test_images").glob("*.jpg") for i, test_image_path in enumerate(test_images): # loaded_img = mpimg.imread(str(test_image_path)) # test_image_path = get_input_path("output_images").joinpath("test1.jpg") loaded_img = mpimg.imread(str(test_image_path)) binary_image = get_binary_image(loaded_img) # show_tresholding_stages(loaded_img, gradx, grady, mag_binary, dir_binary, combined_binary) fig, ax = plt.subplots(2) ax[0].imshow(loaded_img) ax[0].set_title("Loaded Image") ax[1].imshow(binary_image, cmap="gray") ax[1].set_title("Binary Image") if i == 0: plt.imsave( str(get_output_folder_path().joinpath( f"{test_image_path.stem}.jpg")), loaded_img) plt.imsave(str(get_output_folder_path().joinpath( f"{test_image_path.stem}_binary.jpg")), binary_image, cmap="gray") break plt.show()
def main(): test_images = get_input_path("test_images").glob("*.jpg") lane_detector = LaneDetector() for i, test_image_path in enumerate(test_images): test_image_path = get_input_path("test_images").joinpath("test1.jpg") image = mpimg.imread(str(test_image_path)) warp_matrix, img = transform_image(image) leftx, lefty, rightx, righty, out_img = lane_detector.sliding_window(img) left_fitx, right_fitx, plotpy = lane_detector.get_polynominals(out_img, leftx, lefty, rightx, righty) polynominal_image = np.copy(out_img) left_curverad, right_curverad = measure_curvature_real(left_fitx, right_fitx, plotpy) print(f"Left line radius: {left_curverad} m, right lane radius: {right_curverad} m") break
def main(): # test_main() input_video = str(get_input_path("project_video.mp4")) tracked_video = str(get_output_folder_path().joinpath("tracked_video.mp4")) camera_matrix, distortion_coeff = load_camera_precalculated_coefficients() lane_detector = LaneDetector() clip1 = VideoFileClip(input_video) white_clip = clip1.fl_image( lambda image: process_image(image, lane_detector, camera_matrix, distortion_coeff) ) # NOTE: this function expects color images!! white_clip.write_videofile(tracked_video, audio=False)
def main(): """ Main function it an example function """ ret, mtx, dist = calculate_camera_coefficients() print(f"RMS: {ret}") print(f"Camera matrix: {mtx}") print(f"Distortion coefficients: {dist}") save_camera_coefficients(mtx, dist) example_image = get_input_path("test_images").joinpath("test1.jpg") chessboard_image = get_input_path("camera_cal").joinpath("calibration1.jpg") img = cv2.imread(str(example_image)) undistorted = correct_camera_distortion(img, mtx, dist) output_path_undistorted = get_output_folder_path().joinpath(f"{example_image.stem}_undistorted.jpg") output_path_distorted = get_output_folder_path().joinpath(f"{example_image.stem}_distorted.jpg") cv2.imwrite(str(output_path_distorted), img) cv2.imwrite(str(output_path_undistorted), undistorted) cv2.imshow("calibration1", undistorted) cv2.waitKey(1000)
fig, ax = plt.subplots(2) ax[0].plot(Polygon(src_points).get_xy()[:, 0], Polygon(src_points).get_xy()[:, 1], color="red") ax[0].imshow(img) ax[1].plot(Polygon(dest_points).get_xy()[:, 0], Polygon(dest_points).get_xy()[:, 1], color="red") ax[1].imshow(warped) return warped, M if __name__ == "__main__": test_images = get_input_path("test_images").glob("*.jpg") for i, test_image_path in enumerate(test_images): test_image_path = get_input_path("output_images").joinpath( "test1_undistorted.jpg") img = cv2.imread(str(test_image_path)) img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) warped, M = warp_image(img_rgb, True) fig, ax = plt.subplots(2) ax[0].imshow(img_rgb) ax[0].set_title("Unwarped image") ax[1].imshow(warped) ax[1].set_title("Warped image")