Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored master branch #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions LaneDetection/CameraCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ 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,
'dist': dist,
'rvecs': rvecs,
'tvecs': tvecs}

return calibration
Comment on lines -57 to -65
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calculate_camera_calibration refactored with the following changes:



def get_camera_calibration():
"""
Expand Down
5 changes: 1 addition & 4 deletions LaneDetection/ImageProcessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 29-32 refactored with the following changes:

rows = len(images)
cols = 2
fig, axis = plt.subplots(rows, cols)
Expand Down
14 changes: 4 additions & 10 deletions LaneDetection/ImageUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function abs_sobel refactored with the following changes:



def gradient_magnitude(sobel_x, sobel_y):
Expand Down Expand Up @@ -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))
Comment on lines -71 to +69
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function extract_yellow refactored with the following changes:



def extract_dark(img):
Expand All @@ -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))
Comment on lines -83 to +79
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function extract_dark refactored with the following changes:



def extract_highlights(img, p=99.9):
Expand All @@ -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)
Comment on lines -95 to +90
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function extract_highlights refactored with the following changes:



def binary_noise_reduction(img, thresh):
Expand Down
7 changes: 3 additions & 4 deletions LaneDetection/LaneDetector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines -46 to +48
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LaneDetector.__line_plausible refactored with the following changes:


def __check_lines(self, left_x, left_y, right_x, right_y):
"""
Expand Down
10 changes: 4 additions & 6 deletions LaneDetection/Line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Line.is_current_fit_parallel refactored with the following changes:


def get_current_fit_distance(self, other_line):
"""
Expand Down Expand Up @@ -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])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calc_curvature refactored with the following changes: