Exemple #1
0
def run(image_path, output_path):
    image = cv2.imread(image_path)
    image2 = image[:]
    image = OneDHWTLaneDetectorV2.crop_image(image)
    thresh = OneDHWTLaneDetectorV2.pre_process(image)
    row_thresh = int(image.shape[1]/2)

    ll_points = OneDHWTLaneDetectorV2.get_ll_spike_positions(thresh,
                                                             signal_row_start=Params.ROI_HEIGHT - 1, signal_row_end=0,
                                                             signal_col_start=0, signal_col_end=64,
                                                             dbg=debug, row_thresh=row_thresh, image=image2)

    rl_points = OneDHWTLaneDetectorV2.get_rl_spike_positions(thresh,
                                                             signal_row_start=Params.ROI_HEIGHT - 1, signal_row_end=0,
                                                             signal_col_start=(Params.ROI_WIDTH - 64),
                                                             signal_col_end=Params.ROI_WIDTH,
                                                             dbg=debug, row_thresh=row_thresh, image=image2)

    ll_points, rl_points = OneDHWTLaneDetectorV2.filter_cross_points(ll_points, rl_points)

    # filtered_ll_points = OneDHWTLaneDetectorV2.filter_lines(ll_points, -60, -30, dbg=debug)
    # filtered_rl_points = OneDHWTLaneDetectorV2.filter_lines(rl_points, 30, 60, dbg=debug)

    updated_ll_points = [tuple((a + Params.ROI_START_COL, b + Params.ROI_START_ROW)) for a, b in ll_points]
    updated_rl_points = [tuple((a + Params.ROI_START_COL, b + Params.ROI_START_ROW)) for a, b in rl_points]

    if debug:
        print("Filtered ll points: " + str(ll_points))
        print("Filtered rl points: " + str(rl_points))
        print("Updated ll points: " + str(updated_ll_points))
        print("Updated rl points: " + str(updated_rl_points))

    # NumUtils.draw_line(image2, updated_ll_points, (0, 255, 0))
    # NumUtils.draw_line(image2, updated_rl_points, (0, 0, 255))

    # NumUtils.draw_line(image2, filtered_ll_points, (0, 255, 0))
    # NumUtils.draw_line(image2, filtered_rl_points, (0, 0, 255))

    # NumUtils.draw_lanes(image, ll_points, -60, -30, color=(0, 255, 0), thickness=2)
    # NumUtils.draw_lanes(image, rl_points, 30, 60, color=(0, 0, 255), thickness=2)

    # NumUtils.draw_lanes(image2, updated_ll_points, -60, -30, color=(0, 255, 0), thickness=2)
    # NumUtils.draw_lanes(image2, updated_rl_points, 30, 60, color=(0, 0, 255), thickness=2)

    NumUtils.fit_lanes(image2, updated_ll_points, -60, -30, color=(0, 255, 0), thickness=2)
    NumUtils.fit_lanes(image2, updated_rl_points, 30, 60, color=(0, 0, 255), thickness=2)

    cv2.rectangle(image2, (Params.ROI_START_COL, Params.ROI_START_ROW), (Params.ROI_END_COL, Params.ROI_END_ROW), (255, 255, 0))
    cv2.imwrite(output_path, image2)

    del image2
    del image
    del thresh
    del ll_points
    del rl_points