def test_plot_all(self): # calibrate image raw_img = mpimg.imread("quiz_img/signs_vehicles_xygrad.png") cal_fns = glob.glob("camera_cal/calibration??.jpg") cal = lane_line_finding.Calibration(nx=9, ny=6) cal.calibrate_camera_from_filenames(cal_fns) img = cal.undistort_image(raw_img) sobel = lane_line_finding.Sobel() abs_x = sobel.abs_sobel_threshold(img, orient='x', sobel_kernel=9, thresh=(20, 200), plot=False) abs_y = sobel.abs_sobel_threshold(img, orient='y', sobel_kernel=9, thresh=(20, 200), plot=False) mag = sobel.mag_threshold(img, sobel_kernel=11, thresh=(40, 200), plot=False) direction = sobel.dir_threshold(img, sobel_kernel=11, thresh=(0.7, 1.3), plot=False) combined = sobel.plot_all(abs_x, abs_y, mag, direction) if RUN_PLOTTING_TESTS: plt.show()
def test_undistort_image_from_filename_ProperImage(self): fn = "quiz_img/signs_vehicles_xygrad.png" cal = lane_line_finding.Calibration(9, 6) cal.calibrate_camera_from_filenames(self.cal_fns, proj_dir) img = cal.undistort_image_from_filename(fn, proj_dir) if RUN_PLOTTING_TESTS: f, axes = plt.subplots(1, 2, figsize=[16, 6]) axes[0].imshow(mpimg.imread(fn)) axes[0].set_title("Original image") axes[1].imshow(img) axes[1].set_title("Undistorted image") plt.tight_layout() plt.show()
def test_undistort_image_from_filename(self): fn = "camera_cal/calibration4.jpg" cal = lane_line_finding.Calibration(9, 6) cal.calibrate_camera_from_filenames(self.cal_fns, proj_dir) img = cal.undistort_image_from_filename(fn, proj_dir) if RUN_PLOTTING_TESTS: f, axes = plt.subplots(1, 2, figsize=[16, 6]) axes[0].imshow(cv2.imread(fn)) axes[0].set_title("Original image") axes[1].imshow(img) axes[1].set_title("Undistorted image") plt.tight_layout() plt.show()
def test_transform_image(self): # calibrate the camera cal_fns = glob.glob("camera_cal/calibration??.jpg") cal = lane_line_finding.Calibration(9, 6) cal.calibrate_camera_from_filenames(cal_fns, proj_dir) # open a chessboard image fn = "camera_cal/calibration10.jpg" cb = lane_line_finding.Chessboard(fn, proj_dir, 9, 6) # undistort image cb.img = cal.undistort_image(cb.img) # find outer corners of chessboard cb.get_chessboard_corners() src_coords, dst_coords = cb.get_outer_corners() # do a perspective transform pt = lane_line_finding.PerspectiveTransform(src_coords, dst_coords) trans_img = pt.transform_image(cb.img) if RUN_PLOTTING_TESTS: f, axes = plt.subplots(1, 2, figsize=[15, 5]) # plot original (undistorted) image axes[0].imshow(cb.img) axes[0].scatter(src_coords[:, 0], src_coords[:, 1], label='src_coords') axes[0].scatter(dst_coords[:, 0], dst_coords[:, 1], label='dst_coords') axes[0].legend() axes[0].set_title("Original image (undistorted)") axes[1].imshow(trans_img) axes[1].set_title("Transformed image") axes[1].imshow(trans_img) plt.tight_layout() plt.show()
def test_calibrate_camera_from_filenames(self): cal = lane_line_finding.Calibration(9, 6) cal.calibrate_camera_from_filenames(self.cal_fns, proj_dir) self.assertIsNotNone(cal.dist) self.assertIsNotNone(cal.mtx)