def test_init(self): cc = ll.CameraCalibrator(9, 6, 'camera_cal/calibration*.jpg') self.assertEqual(cc.nx, 9, 'nx not initialized') self.assertEqual(cc.ny, 6, 'ny not initialized') self.assertEqual(cc.file_template, \ 'camera_cal/calibration*.jpg', \ 'file_template not initialized') self.assertIsNone(cc.mtx, 'mtx should initialize to None') self.assertIsNone(cc.dist, 'dist should initialize to None')
def test_undistort(self): cc = ll.CameraCalibrator(9, 6, 'camera_cal/calibration*.jpg') img = cv2.imread('test_images/test1.jpg') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) with self.assertRaises(AssertionError): undistorted = cc.undistort([]) undistorted = cc.undistort(gray) self.assertTrue(type(undistorted) is np.ndarray, \ 'undistorted image is not a numpy array') self.assertEqual(gray.shape, undistorted.shape, \ 'undistored image is not same dimensions as original')
import numpy as np import glob import scipy.misc import lanelines as ll # image notes # cv2.imread() BGR # mpimg.imread() RGB # scipy.misc.imread() RGB # plt.imshow(img) or plt.imshow(img, cmap='gray') # CamerCalibrator # use CameraCalibration to read a checkerboard image # save it as cc_initial_checkerboard_image.jpg # undistort it and save it as cc_undistored_checkerboard_image.jpg cc = ll.CameraCalibrator(9, 6, 'camera_cal/calibration*.jpg') img = scipy.misc.imread('camera_cal/calibration2.jpg') scipy.misc.imsave('output_images/cc_initial_checkerboard_image.jpg', img) undistorted = cc.undistort(img) scipy.misc.imsave('output_images/cc_undistorted_checkerboard_image.jpg', \ undistorted) # use CameraCalibration to read a road image # save it as cc_initial_road_image.jpg # undistort it and save it as cc_undistored_road_image.jpg img = scipy.misc.imread('test_images/signs_vehicles_xygrad.png') scipy.misc.imsave('output_images/cc_initial_road_image.jpg', img) undistorted = cc.undistort(img) scipy.misc.imsave('output_images/cc_undistorted_road_image.jpg', \ undistorted) # PerspectiveTransformer
def test_calibrate(self): cc = ll.CameraCalibrator(9, 6, 'camera_cal/calibration*.jpg') cc.calibrate() self.assertIsNotNone(cc.mtx, 'mtx should not be None') self.assertIsNotNone(cc.dist, 'dist should not be None')