Пример #1
0
def main(args):
    scene_manager = SceneManager(args.input_folder)
    scene_manager.load()

    image_ids = map(scene_manager.get_image_from_name,
                    iter(lambda: sys.stdin.readline().strip(), ""))
    scene_manager.delete_images(image_ids)

    scene_manager.save(args.output_folder)
Пример #2
0
def main(args):
    scene_manager = SceneManager(args.input_folder)
    scene_manager.load()

    images = sorted(scene_manager.images.itervalues(), key=image_to_idx)

    if args.method.lower() == "linear":
        new_images = interpolate_linear(images, args.camera_id, args.format)
    else:
        new_images = interpolate_hermite(images, args.camera_id, args.format)

    map(scene_manager.add_image, new_images)

    scene_manager.save(args.output_folder)
Пример #3
0
def main(args):
    scene_manager = SceneManager(args.input_folder)
    scene_manager.load()

    # expect each line of input corresponds to one row
    P = np.array(
        [map(float,
             sys.stdin.readline().strip().split()) for _ in xrange(3)])

    scene_manager.points3D[:] = scene_manager.points3D.dot(P[:, :3].T) + P[:,
                                                                           3]

    # get rotation without any global scaling (assuming isotropic scaling)
    scale = np.cbrt(np.linalg.det(P[:, :3]))
    q_old_from_new = ~Quaternion.FromR(P[:, :3] / scale)

    for image in scene_manager.images.itervalues():
        image.q *= q_old_from_new
        image.tvec = scale * image.tvec - image.R().dot(P[:, 3])

    scene_manager.save(args.output_folder)
Пример #4
0
def main(args):
    scene_manager = SceneManager(args.input_folder)
    scene_manager.load()

    with open(args.output_file, "w") as fid:
        fid.write("NVM_V3\n \n{:d}\n".format(len(scene_manager.images)))

        image_fmt_str = " {:.3f} " + 7 * "{:.7f} "
        for image_id, image in scene_manager.images.iteritems():
            camera = scene_manager.cameras[image.camera_id]
            f = 0.5 * (camera.fx + camera.fy)
            fid.write(args.image_name_prefix + image.name)
            fid.write(
                image_fmt_str.format(*((f, ) + tuple(image.q.q) +
                                       tuple(image.C()))))
            if camera.distortion_func is None:
                fid.write("0 0\n")
            else:
                fid.write("{:.7f} 0\n".format(-camera.k1))

        image_id_to_idx = dict(
            (image_id, i) for i, image_id in enumerate(scene_manager.images))

        fid.write("{:d}\n".format(len(scene_manager.points3D)))
        for i, point3D_id in enumerate(scene_manager.point3D_ids):
            fid.write(
                "{:.7f} {:.7f} {:.7f} ".format(*scene_manager.points3D[i]))
            fid.write(
                "{:d} {:d} {:d} ".format(*scene_manager.point3D_colors[i]))
            keypoints = [(image_id_to_idx[image_id], kp_idx) +
                         tuple(scene_manager.images[image_id].points2D[kp_idx])
                         for image_id, kp_idx in
                         scene_manager.point3D_id_to_images[point3D_id]]
            fid.write("{:d}".format(len(keypoints)))
            fid.write((len(keypoints) * " {:d} {:d} {:.3f} {:.3f}" +
                       "\n").format(*itertools.chain(*keypoints)))
Пример #5
0
def main(args):
    scene_manager = SceneManager(args.input_folder)
    scene_manager.load()
    assert (len(scene_manager.cameras) == 4)

    zed_l = "frame_chess_zed_left_"
    zed_r = "frame_chess_zed_right_"
    zed_count = 0

    for image in scene_manager.images.itervalues():
        if zed_l in image.name:
            zed_count = zed_count + 1

    zed_gt_scale_in_meters = 0.120
    zed_diff_vec = np.zeros((zed_count, 3))

    for image in scene_manager.images.itervalues():
        if zed_l in image.name:
            row_id = int(image.name.split(zed_l, 1)[1][:-4])
            if row_id < zed_count:
                zed_diff_vec[row_id] = zed_diff_vec[row_id] + image.C()

        if zed_r in image.name:
            row_id = int(image.name.split(zed_r, 1)[1][:-4])
            if row_id < zed_count:
                zed_diff_vec[row_id] = zed_diff_vec[row_id] - image.C()

    print(np.linalg.norm(zed_diff_vec, axis=1))
    scale = zed_gt_scale_in_meters / np.median(
        np.linalg.norm(zed_diff_vec, axis=1))

    print("Scaling the model by {}".format(scale))
    scene_manager.points3D[:] = scene_manager.points3D[:] * scale
    for image in scene_manager.images.itervalues():
        image.tvec = image.tvec * scale

    # Print the relative transform from camera 1 to camera 2. [R|t]
    ricoh_image_l_name = "frame_chess_left_{}.png".format(str(0).zfill(4))
    ricoh_image_r_name = "frame_chess_right_{}.png".format(str(0).zfill(4))

    #ricoh_image_l_name = "cubemap_left_cam_001_{}.png".format(str(0).zfill(4))
    #ricoh_image_r_name = "cubemap_right_cam_001_{}.png".format(str(0).zfill(4))

    for image in scene_manager.images.itervalues():
        if ricoh_image_l_name == image.name:
            ricoh_image_l = image

        if ricoh_image_r_name == image.name:
            ricoh_image_r = image

    print("Relative transformation is:")
    rel_pose = np.matmul(ricoh_image_r.Pose(), ricoh_image_l.InvPose())
    np.set_printoptions(suppress=True)
    print(rel_pose)
    print("\nRelative transformation inverse is:")
    print(np.linalg.inv(rel_pose))

    scene_manager.save(args.output_folder)

    # Save rel_pose in the ini settings format.
    pose_save_str = "\n[RicohRelativePose]"
    pose_save_str = pose_save_str + "\nextrinsics = [ " + np.array2string(
        rel_pose, precision=10, separator=';', suppress_small=False).replace(
            "]", "").replace("[", "").replace("\n", "") + " ]"
    pose_save_str = pose_save_str + "\ninput_path =  " + args.input_folder
    pose_save_str = pose_save_str + "\noutput_path =  " + args.output_folder
    pose_save_str = pose_save_str + "\n"

    with open(os.path.join(args.output_folder, "extrinsics.ini"),
              "w") as text_file:
        text_file.write(pose_save_str)