Esempio n. 1
0
def process_image(image, debug=False):
    undistorted = undistort_image(image)
    threshold = combined_threshold(undistorted)
    bird_eye = original2bird_eye(threshold)
    lane_line_params = calc_lane_lines(bird_eye)
    result = draw_lane_lines(undistorted, lane_line_params)

    if debug:
        f, axarr = plt.subplots(3, 2, figsize=(15, 15))
        axarr[0, 0].imshow(undistorted)
        axarr[0, 0].set_title('Undistorted Image')

        axarr[0, 1].imshow(threshold, cmap='gray')
        axarr[0, 1].set_title('Threshold Image')

        axarr[1, 0].imshow(original2bird_eye(undistorted))
        axarr[1, 0].set_title('Bird Eye Image')

        axarr[1, 1].imshow(bird_eye, cmap='gray')
        axarr[1, 1].set_title('Bird Eye threshold Image')

        axarr[2, 0].imshow(lane_line_params['out_img'])
        axarr[2, 0].plot(lane_line_params['left_fit_x'],
                         lane_line_params['plot_y'],
                         color='yellow')
        axarr[2, 0].plot(lane_line_params['right_fit_x'],
                         lane_line_params['plot_y'],
                         color='yellow')
        axarr[2, 0].set_title('Curvature Image')

        axarr[2, 1].imshow(result)
        axarr[2, 1].set_title('Result Image')
        plt.show()

    return result
Esempio n. 2
0
def process_video_frame(image):

    global prev_fit

    undistorted = undistort_image(image)
    threshold = combined_threshold(undistorted)
    bird_eye = original2bird_eye(threshold)
    lane_line_params = calc_lane_lines(bird_eye)

    result = draw_lane_lines(undistorted, lane_line_params)

    return result
def process_image(image):
    
    undistorted = undistort_image(image)
    threshold = combined_threshold(undistorted)
    bird_eye = original2bird_eye(threshold)
    lane_line_params = calc_lane_lines(bird_eye)
    result = draw_lane_lines(undistorted, lane_line_params)

    f, axarr = plt.subplots(2, 2, figsize=(30, 15))
    axarr[0, 0].imshow(undistorted)
    axarr[0, 0].set_title('Undistorted')
    axarr[0, 1].imshow(threshold, cmap='gray')
    axarr[0, 1].set_title('Threshold')
    axarr[1, 0].imshow(lane_line_params['out_img'])
    axarr[1, 0].plot(lane_line_params['left_fit_x'], lane_line_params['plot_y'], color='yellow')
    axarr[1, 0].plot(lane_line_params['right_fit_x'], lane_line_params['plot_y'], color='yellow')
    axarr[1, 0].set_title('Calculated')
    axarr[1, 1].imshow(result)
    axarr[1, 1].set_title('Result')
    plt.show()

    return result
def process_video_frame(image):
    """process the frame and return the processed result"""
    global prev_fit

    undistorted = undistort_image(image)
    threshold = combined_threshold(undistorted)
    bird_eye = original2bird_eye(threshold)
    lane_line_params = calc_lane_lines(bird_eye, prev_fit=prev_fit)

    # Compute confidence by recent two curvature and decide how to search in next frame
    curve = lane_line_params['curvature']
    last_curve = curve_queue[0] if len(curve_queue) else curve
    confident = abs(curve - last_curve) / curve < 0.2
    if not confident:
        prev_fit = False
    else:
        prev_fit = lane_line_params['left_fit'], lane_line_params['right_fit']

    # maintain the latest curves and output an average to draw
    curve_queue.appendleft(curve)
    lane_line_params['curvature'] = sum(curve_queue) / len(curve_queue)

    result = draw_lane_lines(undistorted, lane_line_params, prev_fit=prev_fit)
    return result
Esempio n. 5
0
    # Calculate the new radii of curvature
    left_curvature = cal_curvature(left_fit[0], left_fit[1], y_to_eval)

    return left_curvature


if __name__ == '__main__':

    images = glob.glob('./test_images/*.jpg')

    # show result on test images
    for idx, filename in enumerate(images):
        image = cv2.imread(filename)
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        undistorted = undistort_image(image)
        threshold = combined_threshold(undistorted)
        bird_eye = original2bird_eye(threshold)
        lane_line_params = calc_lane_lines(bird_eye)

        f, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 10))
        ax1.imshow(image)
        ax1.set_title(os.path.basename(filename) + ' Original', fontsize=12)
        ax2.imshow(lane_line_params['out_img'])
        ax2.set_title(os.path.basename(filename) + ' Calculated', fontsize=12)
        ax2.plot(lane_line_params['left_fit_x'],
                 lane_line_params['plot_y'],
                 color='yellow')
        ax2.plot(lane_line_params['right_fit_x'],
                 lane_line_params['plot_y'],
                 color='yellow')
        plt.show()