Esempio n. 1
0
def compare_transformations():

    mtx, dist = calibrate.get_mtx_dist()

    test_images_sl = glob.glob('./test_images/straight_lines*.jpg')
    test_images = glob.glob('./test_images/test*.jpg')

    for test_fname in test_images_sl + test_images:
        img = cv2.imread(test_fname)
        dst = cv2.undistort(img, mtx, dist, None, mtx)
        # Choose a Sobel kernel size
        ksize = 3  # Choose a larger odd number to smooth gradient measurements

        # Apply each of the thresholding functions
        gradx = abs_sobel_thresh(dst,
                                 orient='x',
                                 sobel_kernel=ksize,
                                 thresh=(30, 100))
        grady = abs_sobel_thresh(dst,
                                 orient='y',
                                 sobel_kernel=ksize,
                                 thresh=(30, 100))
        mag_binary = mag_thresh(dst, sobel_kernel=ksize, mag_thresh=(50, 100))
        dir_binary = dir_threshold(dst, sobel_kernel=ksize, thresh=(0.7, 1.2))
        hls_binary = hls_select(dst, thresh=(120, 255))
        hsv_binary = hsv_select(dst, thresh=(120, 255))

        combined = np.zeros_like(dir_binary)
        combined[((gradx == 1) & (grady == 1) & (mag_binary == 1)) |
                 ((hls_binary == 1) & (dir_binary == 1))] = 1

        # Plot the result
        f, ((ax1, ax2, ax3), (ax4, ax5, ax6),
            (ax7, ax8, ax9)) = plt.subplots(3, 3, figsize=(36, 18))
        f.tight_layout()
        ax1.imshow(dst)
        ax1.set_title('Original Image', fontsize=50)
        ax2.imshow(gradx, cmap='gray')
        ax2.set_title('Thresholded Grad. X', fontsize=50)
        ax3.imshow(grady, cmap='gray')
        ax3.set_title('Thresholded Grad. Y', fontsize=50)
        ax4.imshow(mag_binary, cmap='gray')
        ax4.set_title('Thresholded Grad. Mag.', fontsize=50)
        ax5.imshow(dir_binary, cmap='gray')
        ax5.set_title('Thresholded Grad. Dir.', fontsize=50)
        ax6.imshow(combined, cmap='gray')
        ax6.set_title('Combined', fontsize=50)
        ax7.imshow(hls_binary, cmap='gray')
        ax7.set_title('Thresholded HSL', fontsize=50)
        ax8.imshow(hsv_binary, cmap='gray')
        ax8.set_title('Thresholded HSV', fontsize=50)
        ax9.imshow(hsv_binary, cmap='gray')
        ax9.set_title('Thresholded Grad. Y', fontsize=50)
        plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)
        plt.show()
def test():

    mtx, dist = calibrate.get_mtx_dist()

    test_images_sl = glob.glob('./test_images/straight_lines*.jpg')
    test_images = glob.glob('./test_images/test*.jpg')

    i = 0
    for test_fname in test_images_sl + test_images:
        i += 1
        img = cv2.imread(test_fname)
        wrp, udst = undist_warp.warp(img, mtx, dist)
        lines, result = fit(wrp, udst, True, test_mode=True)
        plt.imsave('./output_images/lines' + str(i) + '.png', lines)
        cv2.imwrite('./output_images/result' + str(i) + '.jpg', result)
Esempio n. 3
0
def write_color_transformed_test_images():

    mtx, dist = calibrate.get_mtx_dist()

    test_images_sl = glob.glob('./test_images/straight_lines*.jpg')
    test_images = glob.glob('./test_images/test*.jpg')

    i = 0
    for test_fname in test_images_sl + test_images:
        i += 1
        img = cv2.imread(test_fname)
        dst = cv2.undistort(img, mtx, dist, None, mtx)
        cvt = combine(dst)
        plt.imsave('./output_images/color_transformed' + str(i) + '.png',
                   cvt,
                   cmap=cm.gray)
def write_warped_test_images():

    mtx, dist = calibrate.get_mtx_dist()

    test_images_sl = glob.glob('./test_images/straight_lines*.jpg')
    test_images = glob.glob('./test_images/test*.jpg')

    i = 0
    for test_fname in test_images_sl + test_images:
        i += 1
        img = cv2.imread(test_fname)
        wrp, udst = warp(img, mtx, dist)
        plt.imsave('./output_images/warped' + str(i) + '.png',
                   wrp,
                   cmap=cm.gray)
        #cv2.imwrite('./output_images/warped' + str(i) + '.jpg', wrp)


#calibrate.write_undistorted_test_images()
#color_transform.write_color_transformed_test_images()
#write_warped_test_images()
def image_process(image):
    mtx, dist = calibrate.get_mtx_dist()
    wrp, udst = undist_warp.warp(image, mtx, dist)
    out_img, result = fit(wrp, udst, verbose=False)
    return result