diff --git a/LaneDetection/CameraCalibration.py b/LaneDetection/CameraCalibration.py index 5bf4aabda3..4f782e3178 100644 --- a/LaneDetection/CameraCalibration.py +++ b/LaneDetection/CameraCalibration.py @@ -54,7 +54,7 @@ def calculate_camera_calibration(path_pattern, rows, cols): ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, CAL_IMAGE_SIZE[:-1], None, None) - calibration = {'objpoints': objpoints, + return {'objpoints': objpoints, 'imgpoints': imgpoints, 'cal_images': cal_images, 'mtx': mtx, @@ -62,8 +62,6 @@ def calculate_camera_calibration(path_pattern, rows, cols): 'rvecs': rvecs, 'tvecs': tvecs} - return calibration - def get_camera_calibration(): """ diff --git a/LaneDetection/ImageProcessing.py b/LaneDetection/ImageProcessing.py index 4daed31e6f..f6ae00e833 100644 --- a/LaneDetection/ImageProcessing.py +++ b/LaneDetection/ImageProcessing.py @@ -26,10 +26,7 @@ cam_calibrator = CameraCalibrator(img[:, :, 0].shape[::-1], cam_calibration) ld = LaneDetector(SRC, DST, n_frames=FRAME_MEMORY, cam_calibration=cam_calibrator, transform_offset=OFFSET) - images = [] - for i in range(1, 12): - images.append(imread('../test_images/test%s.jpg' % i)) - + images = [imread('../test_images/test%s.jpg' % i) for i in range(1, 12)] rows = len(images) cols = 2 fig, axis = plt.subplots(rows, cols) diff --git a/LaneDetection/ImageUtils.py b/LaneDetection/ImageUtils.py index 0df84ba092..038e6c24d0 100644 --- a/LaneDetection/ImageUtils.py +++ b/LaneDetection/ImageUtils.py @@ -20,9 +20,7 @@ def abs_sobel(img_ch, orient='x', sobel_kernel=3): raise ValueError('orient has to be "x" or "y" not "%s"' % orient) sobel = cv2.Sobel(img_ch, -1, *axis, ksize=sobel_kernel) - abs_s = np.absolute(sobel) - - return abs_s + return np.absolute(sobel) def gradient_magnitude(sobel_x, sobel_y): @@ -68,9 +66,7 @@ def extract_yellow(img): :return: Yellow 255 not yellow 0 """ hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV) - mask = cv2.inRange(hsv, (20, 50, 150), (40, 255, 255)) - - return mask + return cv2.inRange(hsv, (20, 50, 150), (40, 255, 255)) def extract_dark(img): @@ -80,8 +76,7 @@ def extract_dark(img): :return: Dark 255 not dark 0 """ hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV) - mask = cv2.inRange(hsv, (0, 0, 0.), (255, 153, 128)) - return mask + return cv2.inRange(hsv, (0, 0, 0.), (255, 153, 128)) def extract_highlights(img, p=99.9): @@ -92,8 +87,7 @@ def extract_highlights(img, p=99.9): :return: Highlight 255 not highlight 0 """ p = int(np.percentile(img, p) - 30) - mask = cv2.inRange(img, p, 255) - return mask + return cv2.inRange(img, p, 255) def binary_noise_reduction(img, thresh): diff --git a/LaneDetection/LaneDetector.py b/LaneDetection/LaneDetector.py index 651233e7f7..6b20e7851c 100644 --- a/LaneDetection/LaneDetector.py +++ b/LaneDetection/LaneDetector.py @@ -43,10 +43,9 @@ def __line_plausible(self, left, right): """ if len(left[0]) < 3 or len(right[0]) < 3: return False - else: - new_left = Line(y=left[0], x=left[1]) - new_right = Line(y=right[0], x=right[1]) - return are_lanes_plausible(new_left, new_right) + new_left = Line(y=left[0], x=left[1]) + new_right = Line(y=right[0], x=right[1]) + return are_lanes_plausible(new_left, new_right) def __check_lines(self, left_x, left_y, right_x, right_y): """ diff --git a/LaneDetection/Line.py b/LaneDetection/Line.py index 89f17b7d01..c61654d4d0 100644 --- a/LaneDetection/Line.py +++ b/LaneDetection/Line.py @@ -81,9 +81,7 @@ def is_current_fit_parallel(self, other_line, threshold=(0, 0)): first_coefi_dif = np.abs(self.current_fit[0] - other_line.current_fit[0]) second_coefi_dif = np.abs(self.current_fit[1] - other_line.current_fit[1]) - is_parallel = first_coefi_dif < threshold[0] and second_coefi_dif < threshold[1] - - return is_parallel + return first_coefi_dif < threshold[0] and second_coefi_dif < threshold[1] def get_current_fit_distance(self, other_line): """ @@ -118,6 +116,6 @@ def calc_curvature(fit_cr): y_eval = np.max(y) fit_cr = np.polyfit(y * ym_per_pix, x * xm_per_pix, 2) - curverad = ((1 + (2 * fit_cr[0] * y_eval / 2. + fit_cr[1]) ** 2) ** 1.5) / np.absolute(2 * fit_cr[0]) - - return curverad + return ( + (1 + (2 * fit_cr[0] * y_eval / 2.0 + fit_cr[1]) ** 2) ** 1.5 + ) / np.absolute(2 * fit_cr[0])