Beispiel #1
0
    def calibrate(self,
                  fns,
                  pattern_size,
                  flag_calib=None,
                  debug=False,
                  square_size=1.):
        # calibrate camera
        images = Images(fns)
        self.w, self.h = images.w, images.h
        images.pattern_size = pattern_size
        obj_pnts, img_pnts = images.find_chess_img_pnts(debug)
        print("find points pair: ", len(img_pnts))

        flag_calib = cv.CALIB_FIX_K3 + cv.CALIB_ZERO_TANGENT_DIST
        rms, matrix, dist, rvecs, tvecs = cv.calibrateCamera(
            obj_pnts.transpose(0, 2, 1),
            img_pnts.transpose(0, 2, 1), (images.w, images.h),
            None,
            None,
            flags=flag_calib)
        self.K = matrix
        self.dist = dist
        self.rvecs = np.array(rvecs)
        self.tvecs = np.array(tvecs)
        return obj_pnts, img_pnts, rms
    def camera_trianular(fns, K, dist, pattern_size):
        images_test = Images(fns)
        images_test.pattern_size = pattern_size
        obj_pnts, img_pnts = images_test.find_chess_img_pnts()
        tripoints3d = triangulation_two(img_pnts, K)
        plot_tripoints(tripoints3d)
        plt.savefig("../tri.png")

        camera_test = Camera((w, h), K, dist)
        img_pnts_undistort = camera_test.undistort_points(img_pnts)
        tripoints3d = triangulation_two(img_pnts_undistort, K)
        plot_tripoints(tripoints3d)
        plt.savefig("../tri_undistort.png")

        plt.show()
Beispiel #3
0
    w, h = 1920, 1080
    params = read_fs("./datasets/data/image_cap_mono_3m/camera0.yml", "matrix", "dist")
    fns = ["./datasets/data/image_cap_mono_3m_test/1582708301.25.png", 
            "./datasets/data/image_cap_mono_3m_test/1582708321.31.png"]

    params = read_fs("./datasets/data/image_cap_mono_33cm/camera.yaml", "matrix", "dist")
    fns = ["./datasets/data/image_cap_mono_33cm_test/2.png", 
            "./datasets/data/image_cap_mono_33cm_test/5.png"]
    camera_33 = Camera((w, h), params[0], params[1])

    K = params[0]
    dist = params[1]

    images_test = Images(fns)
    images_test.pattern_size = (6, 9)
    obj_pnts, img_pnts = images_test.find_chess_img_pnts(True)
    tripoints3d = triangulation_two(img_pnts, K, cv.RANSAC, True)
    tripoints3d = triangulation_two(img_pnts, K, cv.RANSAC, False)
    plot_tripoints(tripoints3d)

    # img1 = cv.imread(fns[0], -1)
    # img1_un = cv.undistort(img1, camera_33.K, camera_33.dist, None, None)
    # img2 = cv.imread(fns[1], -1)
    # img2_un = cv.undistort(img2, camera_33.K, camera_33.dist, None, None)
    imgs_undistort = camera_33.undistort_imgs(fns)
    for i, img in enumerate(imgs_undistort):
        name = os.path.basename(fns[i])[:-4]
        cv.imwrite("%s_undistort.jpg" %name, img)

    _, img_pnts_undistort = images_test.find_chess_img_pnts(True, 1, imgs_undistort)
    # tripoints3d = triangulation_two(img_pnts_undistort, K, cv.RANSAC, True)