Ejemplo n.º 1
0
def main():
    video_capture = cv2.VideoCapture(webcam_path)
    ret, mtx, dist, rvecs, tvecs = calibration_utils.calibrate_camera(
        n, m, testdir, fmt)
    while (True):
        ret, frame = video_capture.read()
        #        hl_yellow = binarization.highlight_yellow_lines(frame, yellow_min, yellow_max)
        #        sobel_edge = binarization.edge_detection(frame, kernel)
        #        gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
        #        vehicle_off = vehicle_offset.vehicle_offset(frame)
        #        cv2.imshow('frame-yellow',hl_yellow)
        # B G  R
        #        hough_lines.hough_lines(frame, (0,255,0), 'white')
        #        hough_lines.hough_lines(frame, (255,0,0), 'yellow')
        #        cv2.imshow('frame-white',hl_white)
        #        cv2.imshow('frame-sobel',sobel_edge)
        #        cv2.imshow('frame-gray',gray)
        undist_img = calibration_utils.undistort(frame, mtx, dist)
        #        cv2.imshow('frame-undistorted', undist_img)
        #        hl_yellow = binarization.highlight_yellow_lines(undist_img, yellow_min, yellow_max)
        #        hl_white = binarization.highlight_white_lines(undist_img)
        #        cv2.imshow('frame-yellow',hl_yellow)
        #        cv2.imshow('frame-white',hl_white)
        hl_white_yellow = binarization.white_yellow(undist_img, yellow_min,
                                                    yellow_max)
        #        cv2.imshow('frame-white-yellow',hl_white_yellow)
        ##        birdeye = perspective_utils.birdeye(frame)
        #        birdeye, be_boxes = perspective_karla.birdeye(undist_img)
        birdeye, be_boxes = perspective_karla.birdeye(hl_white_yellow)
        cv2.imshow('frame-birdeye', birdeye)
        cv2.imshow('frame-birdeye-boxes', be_boxes)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    cap.release()
    cv2.destroyAllWindows()
    #     axarray[0].imshow(img, cmap='gray')
    #     for point in src:
    #         axarray[0].plot(*point, '.')
    #     axarray[1].set_title('After perspective transform')
    #     axarray[1].imshow(warped, cmap='gray')
    #     for point in dst:
    #         axarray[1].plot(*point, '.')
    #     for axis in axarray:
    #         axis.set_axis_off()
    #     plt.show()

    return warped, M, Minv


if __name__ == '__main__':

    ret, mtx, dist, rvecs, tvecs = calibrate_camera(
        calib_images_dir='camera_cal')

    # show result on test images
    for test_img in glob.glob('test_images/*.jpg'):
        img = cv2.imread(test_img)

        img_undistorted = undistort(img, mtx, dist, verbose=False)

        img_binary = binarize(img_undistorted, verbose=False)

        img_birdeye, M, Minv = birdeye(cv2.cvtColor(img_undistorted,
                                                    cv2.COLOR_BGR2RGB),
                                       verbose=True)
        axarray[0].imshow(img, cmap='gray')
        for point in src:
            axarray[0].plot(*point, '.')
        axarray[1].set_title('After perspective transform')
        axarray[1].imshow(warped, cmap='gray')
        for point in dst:
            axarray[1].plot(*point, '.')
        for axis in axarray:
            axis.set_axis_off()
        plt.show()

    return warped, M, Minv


if __name__ == '__main__':

    ret, mtx, dist, rvecs, tvecs = calibrate_camera(calib_images_dir='camera_cal')

    # show result on test images
    for test_img in glob.glob('test_images/*.jpg'):

        img = cv2.imread(test_img)

        img_undistorted = undistort(img, mtx, dist, verbose=False)

        img_binary = binarize(img_undistorted, verbose=False)

        img_birdeye, M, Minv = birdeye(cv2.cvtColor(img_undistorted, cv2.COLOR_BGR2RGB), verbose=True)