def process_image(image):

    # Pull out the x and y sizes and make a copy of the image
    ysize = image.shape[0]
    xsize = image.shape[1]
    region_select = np.copy(image)

    # Convert to Grayscale
    image_gray=helpers.grayscale(image)

    # Blurring
    blurred_image = helpers.gaussian_blur(image_gray, parameters.Blurring.kernel_size)

    # Canny Transform
    edges = helpers.canny(blurred_image, parameters.Canny.low_threshold, parameters.Canny.high_threshold)

    # Four sided polygon to mask
    imshape = image.shape
    lower_left = (50, imshape[0])
    upper_left = (400, 320)
    upper_right = (524, 320)
    lower_right = (916, imshape[0])
    parameters.Masking.vertices = np.array([[lower_left, upper_left, upper_right, lower_right]], dtype=np.int32)

    # masking
    masked_edges = helpers.region_of_interest(edges, parameters.Masking.vertices)

    # Run Hough on edge detected image
    hough_lines,raw_hough_lines_img = helpers.hough_lines(masked_edges, parameters.Hough.rho, parameters.Hough.theta, parameters.Hough.threshold,
                             parameters.Hough.min_line_length, parameters.Hough.max_line_gap)

    # classify left and right lane lines
    left_lane_lines, right_lane_lines = helpers.classify_left_right_lanes(hough_lines)

    # Raw hough_lines image
    helpers.draw_lines(raw_hough_lines_img, hough_lines, color=[255, 0, 0], thickness=2)

    # RANSAC fit left and right lane lines
    fitted_left_lane_points = helpers.ransac_fit_hough_lines(left_lane_lines)
    fitted_right_lane_points = helpers.ransac_fit_hough_lines(right_lane_lines)
    helpers.draw_model(image, fitted_left_lane_points, color=[255, 0, 0], thickness=2)
    helpers.draw_model(image, fitted_right_lane_points, color=[255, 0, 0], thickness=2)

    # 1D Interpolator - does not work as good as RANSAC so its commented out
    # interpolated_left_lane_line = helpers.interpolate_hough_lines(left_lane_lines)
    # interpolated_right_lane_line = helpers.interpolate_hough_lines(left_lane_lines)
    # helpers.draw_model(image, interpolated_left_lane_line, color=[255, 0, 0], thickness=2)
    # helpers.draw_model(image, interpolated_right_lane_line, color=[255, 0, 0], thickness=2)

    # superpose images
    # superposed_image = helpers.weighted_img(image, raw_hough_lines_img, α=0.8, β=1., λ=0.)

    return image
def process_image(image):
    # NOTE: The output you return should be a color image (3 channel) for processing video below
    # TODO: put your pipeline here,
    # you should return the final output (image where lines are drawn on lanes)
    hsvMasked = helpers.hsvMaskConv(image)
    gray = helpers.grayscale(hsvMasked)

    # Define a kernel size and apply Gaussian smoothing
    kernel_size = helpers.kernel_size
    blur_gray = helpers.gaussian_blur(gray, kernel_size)

    # Define our parameters for Canny and apply
    low_threshold = helpers.low_threshold
    high_threshold = helpers.high_threshold
    edges = helpers.canny(blur_gray, low_threshold, high_threshold)

    # Next we'll isolate the region of interest to apply the Hough transform upon
    mask = np.zeros_like(edges)
    ignore_mask_color = 255
    (imHeight, imWidth, __) = image.shape
    vertices = np.array([[(.10*imWidth,imHeight),(0.45*imWidth, 0.60*imHeight), (0.55*imWidth, 0.60*imHeight), (0.9*imWidth,imHeight)]], dtype=np.int32)
    masked_edges = helpers.region_of_interest(edges, vertices)

    # Define the Hough transform parameters
    # Make a blank the same size as our image to draw on
    rho = helpers.rho # distance resolution in pixels of the Hough grid
    theta = helpers.theta # angular resolution in radians of the Hough grid
    threshold = helpers.threshold   # minimum number of votes (intersections in Hough grid cell)
    min_line_length = helpers.min_line_length #minimum number of pixels making up a line
    max_line_gap = helpers.max_line_gap    # maximum gap in pixels between connectable line segments

    # Run Hough on edge detected image
    # Output "lines" is an array containing endpoints of detected line segments
    line_img, lines = helpers.hough_lines(masked_edges, rho, theta, threshold, min_line_length, max_line_gap)

    # Draw the lines on the edge image
    result = helpers.weighted_img(line_img, image, α=0.8, β=1., γ=0.)
    return result
Beispiel #3
0
def process_image(image):
    # CONVERT TO GRAYSCALE
    gray = helpers.grayscale(image)
    # APPLY GAUSSIAN BLUR
    kernel_size = 7  # Must be an odd number.
    blur_gray = helpers.gaussian_blur(gray, kernel_size)

    # APPLY CANNY EDGE DETECTOR
    low_threshold = 70
    high_threshold = 140
    edges = helpers.canny(blur_gray, low_threshold, high_threshold)

    # DEFINE REGION OF INTEREST
    imshape = image.shape
    line_height = 330
    vertices = np.array([[(0, imshape[0]), (435, line_height),
                          (540, line_height), (imshape[1], imshape[0])]],
                        dtype=np.int32)

    masked_edges = helpers.region_of_interest(edges, vertices)

    # APPLY HOUGH TRANSFORMATION
    rho = 2  # distance resolution in pixels of the Hough grid
    theta = np.pi / 180  # angular resolution in radians of the Hough grid
    threshold = 50  # minimum number of votes (intersections in Hough grid cell)
    min_line_length = 100  # minimum number of pixels making up a line
    max_line_gap = 100  # maximum gap in pixels between connectable line segments
    # Run Hough on edge detected image
    # Output "lines" is an array containing endpoints of detected line segments
    lines = helpers.hough_lines(masked_edges, rho, theta, threshold,
                                min_line_length, max_line_gap, line_height)

    # Draw the lines on the edge image
    lines_edges = helpers.weighted_img(lines, image, 0.8, 1, 0)

    plt.imshow(lines_edges, cmap='gray')
    return lines_edges
Beispiel #4
0
                          (0.9 * imWidth, imHeight)]],
                        dtype=np.int32)
    masked_edges = helpers.region_of_interest(edges, vertices)

    # Define the Hough transform parameters
    # Make a blank the same size as our image to draw on
    rho = helpers.rho  # distance resolution in pixels of the Hough grid
    theta = helpers.theta  # angular resolution in radians of the Hough grid
    threshold = helpers.threshold  # minimum number of votes (intersections in Hough grid cell)
    min_line_length = helpers.min_line_length  #minimum number of pixels making up a line
    max_line_gap = helpers.max_line_gap  # maximum gap in pixels between connectable line segments
    line_image = np.copy(currentImage) * 0  # creating a blank to draw lines on

    # Run Hough on edge detected image
    # Output "lines" is an array containing endpoints of detected line segments
    line_img, lines = helpers.hough_lines(masked_edges, rho, theta, threshold,
                                          min_line_length, max_line_gap)
    color_edges = np.dstack((masked_edges, masked_edges, masked_edges))
    lines_edges = helpers.weighted_img(line_img,
                                       currentImage,
                                       α=0.8,
                                       β=1.,
                                       γ=0.)

    # #DEBUG code for detecting raw lines - adjustment to hough parameters
    # line_img, lines = helpers.hough_rawLines(masked_edges, rho, theta, threshold, min_line_length, max_line_gap)
    # color_edges = np.dstack((masked_edges, masked_edges, masked_edges))
    # lines_edges = helpers.weighted_img(line_img, color_edges, α=0.8, β=1., γ=0.)

    fig.add_subplot(2, 3, index)
    plt.imshow(lines_edges, cmap='gray')
    index += 1
Beispiel #5
0
    # Four sided polygon to mask
    imshape = image.shape
    lower_left = (50, imshape[0])
    upper_left = (400, 320)
    upper_right = (524, 320)
    lower_right = (916, imshape[0])
    parameters.Masking.vertices = np.array(
        [[lower_left, upper_left, upper_right, lower_right]], dtype=np.int32)

    # masking
    masked_edges = helpers.region_of_interest(edges,
                                              parameters.Masking.vertices)

    # Run Hough on edge detected image
    hough_lines, hough_image = helpers.hough_lines(
        masked_edges, parameters.Hough.rho, parameters.Hough.theta,
        parameters.Hough.threshold, parameters.Hough.min_line_length,
        parameters.Hough.max_line_gap)

    # classify left and right lane lines
    left_lane_lines, right_lane_lines = helpers.classify_left_right_lanes(
        hough_lines)

    # RANSAC fit left and right lane lines
    fitted_left_lane_points = helpers.ransac_fit_hough_lines(left_lane_lines)
    fitted_right_lane_points = helpers.ransac_fit_hough_lines(right_lane_lines)
    helpers.draw_model(image,
                       fitted_left_lane_points,
                       color=[255, 0, 0],
                       thickness=2)
    helpers.draw_model(image,
                       fitted_right_lane_points,