예제 #1
0
def processing(img, object_points, img_points, M, Minv, left_line, right_line):
    #camera calibration, image distortion correction
    undist = utils.cal_undistort(img, object_points, img_points)
    #get the thresholded binary image
    thresholded = thresholding(undist)
    #perform perspective  transform
    thresholded_wraped = cv2.warpPerspective(thresholded,
                                             M,
                                             img.shape[1::-1],
                                             flags=cv2.INTER_LINEAR)

    #perform detection
    if left_line.detected and right_line.detected:
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line_by_previous(
            thresholded_wraped, left_line.current_fit, right_line.current_fit)
    else:
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line(
            thresholded_wraped)
    left_line.update(left_fit)
    right_line.update(right_fit)

    #draw the detected laneline and the information
    area_img = utils.draw_area(undist, thresholded_wraped, Minv, left_fit,
                               right_fit)
    curvature, pos_from_center = utils.calculate_curv_and_pos(
        thresholded_wraped, left_fit, right_fit)
    result = utils.draw_values(area_img, curvature, pos_from_center)

    return result
예제 #2
0
def processing(img, object_points, img_points, M, Minv, left_line, right_line):
    undist = utils.cal_undistort(img, object_points, img_points)
    thresholded = thresholding(undist)
    thresholded_wraped = cv2.warpPerspective(thresholded,
                                             M,
                                             img.shape[1::-1],
                                             flags=cv2.INTER_LINEAR)
    if left_line.detected and right_line.detected:
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line_by_previous(
            thresholded_wraped, left_line.current_fit, right_line.current_fit)
    else:
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line(
            thresholded_wraped)
    left_line.update(left_fit)
    right_line.update(right_fit)

    area_img = utils.draw_area(undist, thresholded_wraped, Minv, left_fit,
                               right_fit)

    curvature, pos_from_center = utils.calculate_curv_and_pos(
        thresholded_wraped, left_fit, right_fit)
    result = utils.draw_values(area_img, curvature, pos_from_center)
    return result
예제 #3
0
def processing(img, M, Minv, left_line, right_line):
    prev_time = time.time()
    img = Image.fromarray(img)
    undist = img
    #get the thresholded binary image
    img = np.array(img)
    blur_img = cv2.GaussianBlur(img, (3, 3), 0)
    Sobel_x_thresh = utils.abs_sobel_thresh(blur_img,
                                            orient='x',
                                            thresh_min=90,
                                            thresh_max=255)
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
    dilated = cv2.dilate(Sobel_x_thresh, kernel, iterations=2)
    #perform perspective  transform
    thresholded_wraped = cv2.warpPerspective(dilated,
                                             M,
                                             img.shape[1::-1],
                                             flags=cv2.INTER_LINEAR)
    #perform detection
    if left_line.detected and right_line.detected:
        left_fit, right_fit = utils.find_line_by_previous(
            thresholded_wraped, left_line.current_fit, right_line.current_fit)
    else:
        left_fit, right_fit = utils.find_line(thresholded_wraped)
    left_line.update(left_fit)
    right_line.update(right_fit)
    # #draw the detected laneline and the information
    undist = Image.fromarray(img)
    area_img = utils.draw_area(undist, thresholded_wraped, Minv, left_fit,
                               right_fit)
    area_img = np.array(area_img)
    curr_time = time.time()
    exec_time = curr_time - prev_time
    info = "time: %.2f ms" % (1000 * exec_time)
    print(info)
    return area_img, thresholded_wraped
예제 #4
0
def processing(img, M, Minv, left_line, right_line):
    #img = RotateClockWise90(img)
    #img = np.rot90(img)
    prev_time = time.time()
    img = Image.fromarray(img)
    undist = img
    #get the thresholded binary image
    img = np.array(img)
    thresholded = thresholding(img)
    #perform perspective  transform
    thresholded_wraped = cv2.warpPerspective(thresholded,
                                             M,
                                             img.shape[1::-1],
                                             flags=cv2.INTER_LINEAR)
    #perform detection
    if left_line.detected and right_line.detected:
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line_by_previous(
            thresholded_wraped, left_line.current_fit, right_line.current_fit)
    else:
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line(
            thresholded_wraped)
    left_line.update(left_fit)
    right_line.update(right_fit)
    # #draw the detected laneline and the information
    undist = Image.fromarray(img)
    area_img, gre1 = utils.draw_area(undist, thresholded_wraped, Minv,
                                     left_fit, right_fit)
    curvature, pos_from_center = utils.calculate_curv_and_pos(
        thresholded_wraped, left_fit, right_fit)
    area_img = np.array(area_img)
    result = utils.draw_values(area_img, curvature, pos_from_center)
    curr_time = time.time()
    exec_time = curr_time - prev_time
    info = "time: %.2f ms" % (1000 * exec_time)
    print(info)
    return result, thresholded_wraped
예제 #5
0
def processing(img, object_points, img_points, M, Minv, left_line, right_line):
    # camera calibration, image distortion correction
    # undist = utils.cal_undistort(img,object_points,img_points)
    cv2.imshow("img", img)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    # 设置阈值下限和上限,去除背景颜色
    lower_red = np.array([80, 0, 0])
    upper_red = np.array([160, 255, 150])

    lower_white = np.array([0, 0, 221])
    upper_white = np.array([180, 30, 255])

    lower_yellow = np.array([100, 43, 46])
    upper_yellow = np.array([120, 255, 255])

    lower_lane = np.array([0, 0, 50])
    upper_lane = np.array([180, 43, 120])
    # 创建掩膜
    # 将原图像和掩膜做位与运算

    white_img = colorMask("white_mask", img, hsv, lower_white, upper_white)
    # yellow_img = colorMask("yellow_mask", img, hsv, lower_yellow, upper_yellow)
    # lane_img = colorMask("lane_mask", img, hsv, lower_lane, upper_lane)

    undist = img
    gray = cv2.cvtColor(white_img, cv2.COLOR_RGB2GRAY)

    ret, binary = cv2.threshold(gray, 200, 255,
                                cv2.THRESH_BINARY | cv2.THRESH_TRIANGLE)
    ret, binary2 = cv2.threshold(gray, 200, 1,
                                 cv2.THRESH_BINARY | cv2.THRESH_TRIANGLE)
    #cv2.imshow("binary", binary)
    rgb = cv2.cvtColor(binary, cv2.COLOR_GRAY2RGB)
    cv2.imshow("rgb", rgb)

    #cv2.imshow("binary2", binary)
    # get the thresholded binary image
    thresholded = thresholding(rgb)
    cv2.imshow("thresholded*255", thresholded * 255)
    #perform perspective  transform
    thresholded_wraped = cv2.warpPerspective(binary2,
                                             M,
                                             img.shape[1::-1],
                                             flags=cv2.INTER_LINEAR)

    cv2.imshow("thresholded_wraped*255", thresholded_wraped * 255)

    #perform detection
    if left_line.detected and right_line.detected:
        print("find line")
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line_by_previous(
            thresholded_wraped, left_line.current_fit, right_line.current_fit)
    else:
        print("no find line")
        left_fit, right_fit, left_lane_inds, right_lane_inds = utils.find_line(
            thresholded_wraped)
    left_line.update(left_fit)
    right_line.update(right_fit)

    #draw the detected laneline and the information
    area_img = utils.draw_area(undist, thresholded_wraped, Minv, left_fit,
                               right_fit)
    cv2.imshow("area_img", area_img)
    cv2.waitKey(50)

    #print(area_img)
    #curvature,pos_from_center = utils.calculate_curv_and_pos(thresholded_wraped,left_fit, right_fit)
    #result = utils.draw_values(area_img,curvature,pos_from_center)
    #result=area_img
    result = rgb
    return result