scripts/detection_util.py
def draw_lane(img, line_segments):
  """
  Segregates line-segments based on their slope to identify which part (left or right) of the lane they belong to.
  Runs a linear-regression on the identified left and right line-segments, and extrapolates those lines until the bottom
  part of the image i.e. x = 0 for left lane-line and y = height-of-image for right lane-line.
  :param line_segments:  Line segments obtained using Hough transform.
  :return:  Image containing marked lanes.
  """
  # Line fit on obtained hough-lines.
  if line_segments is not None:
    left_line_segments = [segment for segment in line_segments if segment.lane_side == Lane.LEFT_LINE]
    right_line_segments = [segment for segment in line_segments if segment.lane_side == Lane.RIGHT_LINE]
    left_line_x, left_line_y = get_x_y_coordinates_as_list(left_line_segments)
    right_line_x, right_line_y = get_x_y_coordinates_as_list(right_line_segments)

    if len(left_line_x) == 0 or len(left_line_y) == 0 or len(right_line_x) == 0 or len(right_line_y) == 0:
      return None

    left_coeffs = np.polyfit(left_line_x, left_line_y, 1)
    right_coeffs = np.polyfit(right_line_x, right_line_y, 1)

    left_line = np.poly1d(left_coeffs)
    right_line = np.poly1d(right_coeffs)

    # Generate left-line and right-line's points.
    # Note: Minimum x-coordinate that can be observed is 0.
    x_left = np.linspace(0, max(left_line_x), 10).astype(int)
    y_left = left_line(x_left).astype(int)
    left_line_pts = list(zip(x_left, y_left))
    # Note: Maximum x-coordinate that can be observed is image's width.
    x_right = np.linspace(min(right_line_x), img.shape[1], 10).astype(int)
    y_right = right_line(x_right).astype(int)
    right_line_pts = list(zip(x_right, y_right))

    lines_img = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8)
    draw_lane_lines(lines_img, left_line_pts, right_line_pts)
    return lines_img

  Segregates line-segments based on their slope to identify which part (left or right) of the lane they belong to.
  Runs a linear-regression on the identified left and right line-segments, and extrapolates those lines until the bottom
  part of the image i.e. x = 0 for left lane-line and y = height-of-image for right lane-line.
  :param line_segments:  Line segments obtained using Hough transform.
  :return:  Image containing marked lanes.
  
Segregates line-segments based on their slope to identify which part (left or right) of the lane they belong to.
Runs a linear-regression on the identified left and right line-segments, and extrapolates those lines until the bottom
part of the image i.e. x = 0 for left lane-line and y = height-of-image for right lane-line.
Segregates line - segments based on their slope to identify which part ( left or right ) of the lane they belong to . Runs a linear - regression on the identified left and right line - segments and extrapolates those lines until the bottom part of the image i . e . x = 0 for left lane - line and y = height - of - image for right lane - line .
def draw_lane(img, line_segments):
  if line_segments is not None:
    left_line_segments = [segment for segment in line_segments if segment.lane_side == Lane.LEFT_LINE]
    right_line_segments = [segment for segment in line_segments if segment.lane_side == Lane.RIGHT_LINE]
    left_line_x, left_line_y = get_x_y_coordinates_as_list(left_line_segments)
    right_line_x, right_line_y = get_x_y_coordinates_as_list(right_line_segments)
    if len(left_line_x) == 0 or len(left_line_y) == 0 or len(right_line_x) == 0 or len(right_line_y) == 0:
      return None
    left_coeffs = np.polyfit(left_line_x, left_line_y, 1)
    right_coeffs = np.polyfit(right_line_x, right_line_y, 1)
    left_line = np.poly1d(left_coeffs)
    right_line = np.poly1d(right_coeffs)
    x_left = np.linspace(0, max(left_line_x), 10).astype(int)
    y_left = left_line(x_left).astype(int)
    left_line_pts = list(zip(x_left, y_left))
    x_right = np.linspace(min(right_line_x), img.shape[1], 10).astype(int)
    y_right = right_line(x_right).astype(int)
    right_line_pts = list(zip(x_right, y_right))
    lines_img = np.zeros((img.shape[0], img.shape[1], 3), dtype=np.uint8)
    draw_lane_lines(lines_img, left_line_pts, right_line_pts)
    return lines_img
def draw_lane ( img , line_segments ) : if line_segments is not None : left_line_segments = [ segment for segment in line_segments if segment . lane_side == Lane . LEFT_LINE ] right_line_segments = [ segment for segment in line_segments if segment . lane_side == Lane . RIGHT_LINE ] left_line_x , left_line_y = get_x_y_coordinates_as_list ( left_line_segments ) right_line_x , right_line_y = get_x_y_coordinates_as_list ( right_line_segments ) if len ( left_line_x ) == 0 or len ( left_line_y ) == 0 or len ( right_line_x ) == 0 or len ( right_line_y ) == 0 : return None left_coeffs = np . polyfit ( left_line_x , left_line_y , 1 ) right_coeffs = np . polyfit ( right_line_x , right_line_y , 1 ) left_line = np . poly1d ( left_coeffs ) right_line = np . poly1d ( right_coeffs ) x_left = np . linspace ( 0 , max ( left_line_x ) , 10 ) . astype ( int ) y_left = left_line ( x_left ) . astype ( int ) left_line_pts = list ( zip ( x_left , y_left ) ) x_right = np . linspace ( min ( right_line_x ) , img . shape [ 1 ] , 10 ) . astype ( int ) y_right = right_line ( x_right ) . astype ( int ) right_line_pts = list ( zip ( x_right , y_right ) ) lines_img = np . zeros ( ( img . shape [ 0 ] , img . shape [ 1 ] , 3 ) , dtype = np . uint8 ) draw_lane_lines ( lines_img , left_line_pts , right_line_pts ) return lines_img
Segregates line-segments based on their slope to identify which part (left or right) of the lane they belong to.
Segregates line - segments based on their slope to identify which part ( left or right ) of the lane they belong to .
"""
  Segregates line-segments based on their slope to identify which part (left or right) of the lane they belong to.
  Runs a linear-regression on the identified left and right line-segments, and extrapolates those lines until the bottom
  part of the image i.e. x = 0 for left lane-line and y = height-of-image for right lane-line.
  :param line_segments:  Line segments obtained using Hough transform.
  :return:  Image containing marked lanes.
  """ # Line fit on obtained hough-lines. # Generate left-line and right-line's points. # Note: Minimum x-coordinate that can be observed is 0. # Note: Maximum x-coordinate that can be observed is image's width.
Image containing marked lanes.
Image containing marked lanes .
img
line_segments
Line segments obtained using Hough transform.
Line segments obtained using Hough transform .