Beispiel #1
0
def shot_from_json(key, obj, cameras):
    """
    Read shot from a json object
    """
    pose = types.Pose()
    pose.rotation = obj["rotation"]
    if "translation" in obj:
        pose.translation = obj["translation"]

    metadata = types.ShotMetadata()
    metadata.orientation = obj.get("orientation")
    metadata.capture_time = obj.get("capture_time")
    metadata.gps_dop = obj.get("gps_dop")
    metadata.gps_position = obj.get("gps_position")

    shot = types.Shot()
    shot.id = key
    shot.metadata = metadata
    shot.pose = pose
    shot.camera = cameras.get(obj["camera"])

    if 'scale' in obj:
        shot.scale = obj['scale']
    if 'covariance' in obj:
        shot.covariance = np.array(obj['covariance'])
    if 'merge_cc' in obj:
        shot.merge_cc = obj['merge_cc']
    if 'vertices' in obj and 'faces' in obj:
        shot.mesh = types.ShotMesh()
        shot.mesh.vertices = obj['vertices']
        shot.mesh.faces = obj['faces']

    return shot
Beispiel #2
0
    def run(self, args):
        start = time.time()
        data = dataset.DataSet(args.dataset)

        try:
            graph = data.load_tracks_graph()
            reconstructions = data.load_reconstruction()
        except IOError:
            print 'mesh.py: Failed to load reconstructions or tracks graph. May be missing...'
            return

        for i, r in enumerate(reconstructions):
            for shot in r.shots.values():
                if shot.id in graph:
                    vertices, faces = mesh.triangle_mesh(
                        shot.id, r, graph, data)
                    shot.mesh = types.ShotMesh()
                    shot.mesh.vertices = vertices
                    shot.mesh.faces = faces

        data.save_reconstruction(reconstructions,
                                 filename='reconstruction.meshed.json',
                                 minify=True)

        end = time.time()
        with open(data.profile_log(), 'a') as fout:
            fout.write('mesh: {0}\n'.format(end - start))
Beispiel #3
0
def run(data):
    start = time.time()
    graph = data.track_graph_of_images
    reconstructions = data.reconstructions

    for i, r in enumerate(reconstructions):
        for shot in r.shots.values():
            if shot.id in graph:
                vertices, faces = mesh.triangle_mesh(shot.id, r, graph, data)
                shot.mesh = types.ShotMesh()
                shot.mesh.vertices = vertices
                shot.mesh.faces = faces

    data.save_reconstruction(reconstructions,
                             filename='reconstruction.meshed.json',
                             minify=True)

    end = time.time()
    with open(data.profile_log(), 'a') as fout:
        fout.write('mesh: {0}\n'.format(end - start))
Beispiel #4
0
    def run(self, args):
        start = time.time()
        data = dataset.DataSet(args.dataset)
        graph = data.load_tracks_graph()
        reconstructions = data.load_reconstruction()

        for i, r in enumerate(reconstructions):
            for shot in r.shots.values():
                if shot.id in graph:
                    vertices, faces = mesh.triangle_mesh(shot.id, r, graph,
                                                         data)
                    shot.mesh = types.ShotMesh()
                    shot.mesh.vertices = vertices
                    shot.mesh.faces = faces

        data.save_reconstruction(reconstructions,
                                 filename='reconstruction.meshed.json')

        end = time.time()
        with open(data.profile_log(), 'a') as fout:
            fout.write('mesh: {0}\n'.format(end - start))
Beispiel #5
0
    def run(self, args):
        start = time.time()
        data = dataset.DataSet(args.dataset)
        tracks_manager = data.load_tracks_manager()
        reconstructions = data.load_reconstruction()

        all_shot_ids = set(tracks_manager.get_shot_ids())
        for i, r in enumerate(reconstructions):
            for shot in r.shots.values():
                if shot.id in all_shot_ids:
                    vertices, faces = mesh.triangle_mesh(
                        shot.id, r, tracks_manager, data)
                    shot.mesh = types.ShotMesh()
                    shot.mesh.vertices = vertices
                    shot.mesh.faces = faces

        data.save_reconstruction(reconstructions,
                                 filename='reconstruction.meshed.json',
                                 minify=True)

        end = time.time()
        with open(data.profile_log(), 'a') as fout:
            fout.write('mesh: {0}\n'.format(end - start))
    try:
        # with open(seg_path + '/OpenSfM/' + 'reconstruction{:02d}.json'.format(label)) as f:
        reconstructions = data.load_reconstruction()
    except:
        reconstruction.incremental_reconstruction(data,
                                                  graph=graphs[label],
                                                  my_init=my_init)
        reconstructions = data.load_reconstruction()

    if (save_mesh):
        for i, r in enumerate(reconstructions):
            for shot in r.shots.values():
                if shot.id in graphs[label]:
                    vertices, faces = mesh.triangle_mesh(
                        shot.id, r, graphs[label], data)
                    shot.mesh = types.ShotMesh()
                    shot.mesh.vertices = vertices
                    shot.mesh.faces = faces
        data.save_reconstruction(reconstructions,
                                 filename='reconstruction.meshed.json')

    scene_reconstructions[label] = reconstructions

    if (len(reconstructions) == 1):
        """there is only one reconstruction for this, probably good"""
        reconstruct = reconstructions[0]
    else:
        print "have trouble with reconstruction of label {:d}".format(label)

# ## merge reconstructions together
# util.MySceneCanvas(scene_reconstructions, data, K)