Advanced_Lane_Finding_v2.py
def segment(img):
    """
    Main function to segment the lane lines:
    :param img: RGB image
    :return: Binary segmented image with the lane lines
    """

    # 1. Gaussian Blur
    img = img.copy()
    img = gaussian_blur(img, 2)

    # 2. Convert to HLS color space and separate the S channel
    hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS)
    s = hls[:, :, 2]

    # 3. Threshold o the image gradient
    # Grayscale image
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    # Apply each of the thresholding functions
    gradx = abs_sobel_thresh(gray, orient='x', thresh_min=10, thresh_max=255)
    grady = abs_sobel_thresh(gray, orient='y', thresh_min=60, thresh_max=255)
    mag_binary = mag_thresh(gray, thresh_min=60, thresh_max=255)
    dir_binary = dir_threshold(gray, thresh_min=.65, thresh_max= 1.05)

    # Combine all the thresholded images for the gradients
    combined = np.zeros_like(dir_binary)
    combined[((gradx == 1) & (grady == 1)) | ((mag_binary == 1) & (dir_binary == 1))] = 1

    # 4. Threshold color channel
    s_binary = np.zeros_like(combined)
    s_binary[(s > 120) & (s < 255)] = 1

    # Combines color and gradient binary images
    color_binary = np.zeros_like(combined)
    color_binary[(s_binary > 0) | (combined > 0)] = 1

    # Define the region parameters taken from https://github.com/wonjunee/Advanced-Lane-Finding

    imshape = img.shape
    left_bottom = (100, imshape[0])
    right_bottom = (imshape[1] - 20, imshape[0])
    apex1 = (610, 410)
    apex2 = (680, 410)

    inner_left_bottom = (310, imshape[0])
    inner_right_bottom = (1150, imshape[0])
    inner_apex1 = (700, 480)
    inner_apex2 = (650, 480)

    vertices = np.array([[left_bottom, apex1, apex2,                           right_bottom, inner_right_bottom,                           inner_apex1, inner_apex2, inner_left_bottom]], dtype=np.int32)
    # Masked area
    color_binary = region_of_interest(color_binary, vertices)

    return color_binary

    Main function to segment the lane lines:
    :param img: RGB image
    :return: Binary segmented image with the lane lines
    
Main function to segment the lane lines.
Main function to segment the lane lines .
def segment(img):
    img = img.copy()
    img = gaussian_blur(img, 2)
    hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS)
    s = hls[:, :, 2]
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
    gradx = abs_sobel_thresh(gray, orient='x', thresh_min=10, thresh_max=255)
    grady = abs_sobel_thresh(gray, orient='y', thresh_min=60, thresh_max=255)
    mag_binary = mag_thresh(gray, thresh_min=60, thresh_max=255)
    dir_binary = dir_threshold(gray, thresh_min=.65, thresh_max= 1.05)
    combined = np.zeros_like(dir_binary)
    combined[((gradx == 1) & (grady == 1)) | ((mag_binary == 1) & (dir_binary == 1))] = 1
    s_binary = np.zeros_like(combined)
    s_binary[(s > 120) & (s < 255)] = 1
    color_binary = np.zeros_like(combined)
    color_binary[(s_binary > 0) | (combined > 0)] = 1
    imshape = img.shape
    left_bottom = (100, imshape[0])
    right_bottom = (imshape[1] - 20, imshape[0])
    apex1 = (610, 410)
    apex2 = (680, 410)
    inner_left_bottom = (310, imshape[0])
    inner_right_bottom = (1150, imshape[0])
    inner_apex1 = (700, 480)
    inner_apex2 = (650, 480)
    vertices = np.array([[left_bottom, apex1, apex2,                           right_bottom, inner_right_bottom,                           inner_apex1, inner_apex2, inner_left_bottom]], dtype=np.int32)
    color_binary = region_of_interest(color_binary, vertices)
    return color_binary
def segment ( img ) : img = img . copy ( ) img = gaussian_blur ( img , 2 ) hls = cv2 . cvtColor ( img , cv2 . COLOR_RGB2HLS ) s = hls [ : , : , 2 ] gray = cv2 . cvtColor ( img , cv2 . COLOR_RGB2GRAY ) gradx = abs_sobel_thresh ( gray , orient = 'x' , thresh_min = 10 , thresh_max = 255 ) grady = abs_sobel_thresh ( gray , orient = 'y' , thresh_min = 60 , thresh_max = 255 ) mag_binary = mag_thresh ( gray , thresh_min = 60 , thresh_max = 255 ) dir_binary = dir_threshold ( gray , thresh_min = .65 , thresh_max = 1.05 ) combined = np . zeros_like ( dir_binary ) combined [ ( ( gradx == 1 ) & ( grady == 1 ) ) | ( ( mag_binary == 1 ) & ( dir_binary == 1 ) ) ] = 1 s_binary = np . zeros_like ( combined ) s_binary [ ( s > 120 ) & ( s < 255 ) ] = 1 color_binary = np . zeros_like ( combined ) color_binary [ ( s_binary > 0 ) | ( combined > 0 ) ] = 1 imshape = img . shape left_bottom = ( 100 , imshape [ 0 ] ) right_bottom = ( imshape [ 1 ] - 20 , imshape [ 0 ] ) apex1 = ( 610 , 410 ) apex2 = ( 680 , 410 ) inner_left_bottom = ( 310 , imshape [ 0 ] ) inner_right_bottom = ( 1150 , imshape [ 0 ] ) inner_apex1 = ( 700 , 480 ) inner_apex2 = ( 650 , 480 ) vertices = np . array ( [ [ left_bottom , apex1 , apex2 , right_bottom , inner_right_bottom , inner_apex1 , inner_apex2 , inner_left_bottom ] ] , dtype = np . int32 ) color_binary = region_of_interest ( color_binary , vertices ) return color_binary
Main function to segment the lane lines:
Main function to segment the lane lines :
"""
    Main function to segment the lane lines:
    :param img: RGB image
    :return: Binary segmented image with the lane lines
    """ # 1. Gaussian Blur # 2. Convert to HLS color space and separate the S channel # 3. Threshold o the image gradient # Grayscale image # Apply each of the thresholding functions # Combine all the thresholded images for the gradients # 4. Threshold color channel # Combines color and gradient binary images # Define the region parameters taken from https://github.com/wonjunee/Advanced-Lane-Finding # Masked area
Binary segmented image with the lane lines
Binary segmented image with the lane lines
img
None