Example #1
0
def test_image_frame():
    _, image = test_images[0]
    text_output = []
    # Step1: Undistort image using the camera calibration
    undistorted_img = _camera_calibrator.undistort(image)

    # Step2: Apply perspective transformation to create a warped image
    color_warped = _perspective_transformer.warp_image(undistorted_img, M)

    # Step3: Use color transforms, gradients, etc., to create a thresholded binary image
    binary_warped, binary_arr = ImageUtil.binary_thresholded_image(color_warped)
    image_shape = binary_warped.shape
    lane_detection_output = visualize_binary_thresholded_image(color_warped, binary_warped, binary_arr[0], binary_arr[1])
Example #2
0
def process_frame(frame_img, debug=False):
    """ Main method for processing each image frame of a video file """
    text_output = []
    # Step1: Undistort image using the camera calibration
    undistorted_img = _camera_calibrator.undistort(frame_img)

    # Step2: Apply perspective transformation to create a warped image
    color_warped = _perspective_transformer.warp_image(undistorted_img, M)

    # Step3: Use color transforms, gradients, etc., to create a thresholded binary image
    binary_warped, binary_arr = ImageUtil.binary_thresholded_image(color_warped)
    image_shape = binary_warped.shape
    lane_detection_output = visualize_binary_thresholded_image(color_warped, binary_warped, binary_arr[0], binary_arr[1])

    # Step4: Get the sliding window polynomials for the left and right line
    leftx, lefty, rightx, righty = _lane.find_lane_pixels(binary_warped)

    ploty = np.linspace(0, image_shape[0] - 1, image_shape[0])


    left_fitx = _lane.left.polyfit_lines(leftx, lefty, image_shape)

    right_fitx = _lane.right.polyfit_lines(rightx, righty, image_shape)

    # Step5: Overlay the warped image to the original image
    overlay_img = _lane.overlay_image(binary_warped, frame_img, Minv, left_fitx, right_fitx, ploty)
    result = overlay_to_original_image(overlay_img, frame_img)

    # Step6: curvature_and_vehicle_position
    vehicle_position = _lane.get_vehicle_position(image_shape)
    radius_of_curvature = _lane.get_radius_of_curvature()

    text_output.append('Radius of curvature: {} m'.format(radius_of_curvature))
    text_output.append('Vehicle: {}'.format(vehicle_position))
    text_output.append('');
    text_output.append('Left line curve:')
    text_output.append('{:.2}, {:.2}, {:.2}'.format(_lane.left.line_fit0_queue[0], _lane.left.line_fit1_queue[0], _lane.left.line_fit2_queue[0]))
    text_output.append('');
    text_output.append('Right line curve:')
    text_output.append('{:.2}, {:.2}, {:.2}'.format(_lane.right.line_fit0_queue[0], _lane.right.line_fit1_queue[0], _lane.right.line_fit2_queue[0]))
    text_output.append('');
    if _lane.left.detected == False: text_output.append('!!!Left lane not detected!!!')
    if _lane.right.detected == False: text_output.append('!!!Right lane not detected!!!')

    console_img = ImageUtil.image_console(result, frame_img, undistorted_img, lane_detection_output, overlay_img,
                             text_output)
    return console_img
Example #3
0
    if show_title: ax4.set_title('Combined thresholds', fontsize=16)
#    ax4.imshow(combined_binary, cmap='gray')
    # plt.show()

    f.canvas.draw()
    data = np.fromstring(f.canvas.tostring_rgb(), dtype=np.uint8, sep='')
    data = data.reshape(f.canvas.get_width_height()[::-1] + (3,))

    return data

for image_path in glob.glob(TEST_IMAGES_PATH):
    image = cv2.imread(image_path)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    undistorted_img = _camera_calibrator.undistort(image)
    color_warped = _perspective_transformer.warp_image(undistorted_img, M)
    binary_warped, binary_arr = ImageUtil.binary_thresholded_image(color_warped)
    # visualize_binary_thresholded_image(color_warped, binary_warped, binary_arr[0], binary_arr[1], True)

def visualize_peaks_in_binary_warped_image():
    f, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4))
    f.tight_layout(w_pad=4.0)
    ax1.set_title('Warped binary image', fontsize=16)
#    ax1.imshow(binary_warped, cmap='gray')
    histogram = np.sum(binary_warped[binary_warped.shape[0]/2:,:], axis=0)
    ax2.plot(histogram)
    ax2.set_title('Histogram of lower half image', fontsize=16)
    ax2.set_xlabel('Pixel positions')
    ax2.set_ylabel('Counts')
    # plt.show()

# visualize_peaks_in_binary_warped_image()