MCPcopy
hub / github.com/mapillary/OpenSfM / export

Method export

opensfm/commands/export_visualsfm.py:48–124  ·  view source on GitHub ↗
(self, reconstruction, tracks_manager, udata, with_points, export_only)

Source from the content-addressed store, hash-verified

46 self.export(reconstructions[0], tracks_manager, udata, args.points, export_only)
47
48 def export(self, reconstruction, tracks_manager, udata, with_points, export_only):
49 lines = ['NVM_V3', '', len(reconstruction.shots)]
50 shot_size_cache = {}
51 shot_index = {}
52 i = 0
53 skipped_shots = 0
54
55 for shot in reconstruction.shots.values():
56 if export_only is not None and not shot.id in export_only:
57 skipped_shots += 1
58 continue
59
60 q = tf.quaternion_from_matrix(shot.pose.get_rotation_matrix())
61 o = shot.pose.get_origin()
62
63 shot_size_cache[shot.id] = udata.undistorted_image_size(shot.id)
64 shot_index[shot.id] = i
65 i += 1
66
67 if type(shot.camera) == types.BrownPerspectiveCamera:
68 # Will approximate Brown model, not optimal
69 focal_normalized = (shot.camera.focal_x + shot.camera.focal_y) / 2.0
70 else:
71 focal_normalized = shot.camera.focal
72
73 words = [
74 self.image_path(shot.id, udata),
75 focal_normalized * max(shot_size_cache[shot.id]),
76 q[0], q[1], q[2], q[3],
77 o[0], o[1], o[2],
78 '0', '0',
79 ]
80 lines.append(' '.join(map(str, words)))
81
82 # Adjust shots count
83 lines[2] = str(lines[2] - skipped_shots)
84
85 if with_points:
86 skipped_points = 0
87 lines.append('')
88 points = reconstruction.points
89 lines.append(len(points))
90 points_count_index = len(lines) - 1
91
92 for point_id, point in iteritems(points):
93 shots = reconstruction.shots
94 coord = point.coordinates
95 color = list(map(int, point.color))
96
97 view_line = []
98 for shot_key, obs in tracks_manager.get_track_observations(point_id).items():
99 if export_only is not None and not shot_key in export_only:
100 continue
101
102 if shot_key in shots.keys():
103 v = obs.point
104 x = (0.5 + v[0]) * shot_size_cache[shot_key][1]
105 y = (0.5 + v[1]) * shot_size_cache[shot_key][0]

Callers 1

runMethod · 0.95

Calls 5

image_pathMethod · 0.95
mapFunction · 0.85
get_rotation_matrixMethod · 0.80
get_originMethod · 0.80

Tested by

no test coverage detected