Skip to content

Commit 2cbe539

Browse files
author
Brook Roberts
committed
Allow reconstruction step to allow images to be added
1 parent 3e55c94 commit 2cbe539

4 files changed

Lines changed: 42 additions & 17 deletions

File tree

bin/clean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ mv -vf $1/navigation_graph.json $trash
1515
mv -vf $1/plot_inliers $trash
1616
mv -vf $1/depthmaps $trash
1717
mv -vf $1/tracks.csv $trash
18+
mv -vf $1/track_sets.pkl $trash

opensfm/dataset.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -329,18 +329,18 @@ def find_matches(self, im1, im2):
329329
return im2_matches[im1][:, [1, 0]]
330330
return []
331331

332-
def __unionfind_file(self, filename=None):
332+
def __track_sets_file(self, filename=None):
333333
"""Return path of unionfind file"""
334-
return os.path.join(self.data_path, filename or 'unionfind.pkl')
334+
return os.path.join(self.data_path, filename or 'track_sets.pkl')
335335

336-
def load_unionfind_file(self, filename=None):
336+
def load_track_sets_file(self, filename=None):
337337
"""Return unionfind of tracks"""
338-
with open(self.__unionfind_file(filename)) as fin:
339-
return load_unionfind_file(fin)
338+
with open(self.__track_sets_file(filename)) as fin:
339+
return load_track_sets_file(fin)
340340

341-
def save_unionfind_file(self, unionfind, filename=None):
342-
with open(self.__unionfind_file(filename), 'w') as fout:
343-
save_unionfind_file(fout, unionfind)
341+
def save_track_sets_file(self, unionfind, filename=None):
342+
with open(self.__track_sets_file(filename), 'w') as fout:
343+
save_track_sets_file(fout, unionfind)
344344

345345
def __tracks_graph_file(self, filename=None):
346346
"""Return path of tracks file"""
@@ -515,8 +515,8 @@ def save_tracks_graph(fileobj, graph):
515515
fileobj.write('%s\t%s\t%d\t%g\t%g\t%g\t%g\t%g\n' % (
516516
str(image), str(track), fid, x, y, r, g, b))
517517

518-
def load_unionfind_file(fileobj):
518+
def load_track_sets_file(fileobj):
519519
return pickle.load(fileobj)
520520

521-
def save_unionfind_file(fileobj, unionfind):
521+
def save_track_sets_file(fileobj, unionfind):
522522
pickle.dump(unionfind, fileobj, protocol=pickle.HIGHEST_PROTOCOL)

opensfm/matching.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ def create_tracks_graph(features, colors, matches, config, data):
146146
logger.debug('Merging features onto tracks')
147147

148148
try:
149-
uf = data.load_unionfind_file()
149+
uf, track_ids, max_id = data.load_track_sets_file()
150150
except IOError:
151151
uf = UnionFind()
152+
track_ids = {}
153+
max_id = 0
152154

153155
for im1, im2 in matches:
154156
for f1, f2 in matches[im1, im2]:
@@ -161,14 +163,17 @@ def create_tracks_graph(features, colors, matches, config, data):
161163
sets[p].append(i)
162164
else:
163165
sets[p] = [i]
166+
if p not in track_ids:
167+
track_ids[p] = max_id
168+
max_id += 1
164169

165-
data.save_unionfind_file(uf)
166-
167-
tracks = [t for t in sets.values() if good_track(t, config.get('min_track_length', 2))]
170+
track_sets = (uf, track_ids, max_id)
171+
data.save_track_sets_file(track_sets)
172+
tracks = [(track_ids[track_name], t) for track_name, t in sets.iteritems() if good_track(t, config.get('min_track_length', 2))]
168173
logger.debug('Good tracks: {}'.format(len(tracks)))
169174

170175
tracks_graph = nx.Graph()
171-
for track_id, track in enumerate(tracks):
176+
for track_id, track in tracks:
172177
for image, featureid in track:
173178
if image not in features:
174179
continue

opensfm/reconstruction.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,32 @@ def incremental_reconstruction(data):
905905
data.invent_reference_lla()
906906

907907
graph = data.load_tracks_graph()
908+
909+
try:
910+
existing_reconstructions = data.load_reconstruction()
911+
# we remove any points that were in the previous reconstruction but are no longer in our graph
912+
for reconstruction in existing_reconstructions:
913+
reconstruction.points = {k: point for k, point in reconstruction.points.iteritems() if k in graph}
914+
except IOError:
915+
existing_reconstructions = []
916+
917+
reconstructed_images = set(image for reconstruction in existing_reconstructions for image in reconstruction.shots.keys())
918+
908919
tracks, images = matching.tracks_and_images(graph)
909-
remaining_images = set(images)
920+
remaining_images = set(images) - reconstructed_images
910921
gcp = None
911922
if data.ground_control_points_exist():
912923
gcp = data.load_ground_control_points()
913-
common_tracks = matching.all_common_tracks(graph, tracks)
924+
914925
reconstructions = []
926+
for reconstruction in existing_reconstructions:
927+
grow_reconstruction(data, graph, reconstruction, remaining_images, gcp)
928+
reconstructions.append(reconstruction)
929+
reconstructions = sorted(reconstructions,
930+
key=lambda x: -len(x.shots))
931+
data.save_reconstruction(reconstructions)
932+
933+
common_tracks = matching.all_common_tracks(graph, tracks)
915934
pairs = compute_image_pairs(common_tracks, data.config)
916935
for im1, im2 in pairs:
917936
if im1 in remaining_images and im2 in remaining_images:

0 commit comments

Comments
 (0)