def colorThresholding(img_name, mtx, dist, M, thresholds=(60, 255)):
    # preprocess image
    warped = warpImage(img_name, mtx, dist, M, hls=1)

    # thresholding
    img_bin = np.zeros_like(warped)
    img_bin[(warped >= thresholds[0]) & (warped <= thresholds[1])] = 1

    return img_bin
Exemple #2
0
def colorThresholding(img_name, thresholds=(60, 255)):
    mtx, dist, M, offset = loadCalibrationVariables()

    # preprocess image
    warped = warpImage(img_name, mtx, dist, M, hls=1)

    # thresholding
    img_bin = np.zeros_like(warped)
    img_bin[(warped >= thresholds[0]) & (warped <= thresholds[1])] = 1

    return img_bin
def gradThresholding(img_name, mtx, dist, M, thresholds=(20, 100)):
    # preprocess image
    warped = warpImage(img_name, mtx, dist, M)

    # compute x-wise gradient and take the absolute value
    sobel_x = cv2.Sobel(warped, cv2.CV_64F, 1, 0)
    sobel_x_abs = np.absolute(sobel_x)

    # scale the absolute values
    scaled = np.uint8(255 * sobel_x_abs / np.max(sobel_x_abs))

    # apply thresholding
    sobel_bin = np.zeros_like(scaled)
    sobel_bin[(scaled >= thresholds[0]) & (scaled <= thresholds[1])] = 1

    return sobel_bin
Exemple #4
0
    white_3 = cv2.inRange(warped, (200, 200, 200), (255, 255, 255))

    bit_layer = img_bin | yellow | white | white_2 | white_3

    return bit_layer - 1


if __name__ == "__main__":
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    # COLOR THRESHOLDING
    #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    mtx, dist, M, offset = loadCalibrationVariables()

    # load, extract S channel, and warp example image
    img_name = "test_images/test2.jpg"
    img_warp = warpImage(img_name, mtx, dist, M, hls=1)

    # initialise binary image
    img_bin = np.zeros_like(img_warp)

    # select thresolds
    S_thresholds = (60, 255)
    img_bin[(img_warp >= S_thresholds[0]) & (img_warp <= S_thresholds[1])] = 1

    # plot images
    sns.set_style("white")
    fig = plt.figure(1, figsize=(9, 3))
    fig.clf()
    ax1 = fig.add_subplot(121)
    ax1.imshow(img_warp, cmap='gray')
    ax1.set_xlabel("$x$")