Skip to content

Commit

Permalink
Allow to import only list.txt from bundler.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulinus committed Jan 28, 2015
1 parent 1da6e5f commit fdd311b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
22 changes: 9 additions & 13 deletions bin/import_bundler
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,21 @@ if __name__ == "__main__":
parser.add_argument('--bundleout', help='the bundle.out file')
args = parser.parse_args()

# Assume that bundle.out, list.txt and all the images are in datapath
data_path = args.dataset

# converting reconstruction from bundler to OpenSfM reconstruction
if args.list:
list_file = args.list
else:
list_file = os.path.join(data_path, 'list.txt')
if args.bundleout:
bundle_file = args.bundleout
else:
bundle_file = os.path.join(data_path, 'bundle.out')
if os.path.exists(bundle_file) and os.path.exists(list_file):
list_file = 'list.txt'

if not args.bundleout:
print "No bundle.out given. Importing only the list of images list.txt."

if os.path.exists(list_file):
print 'Converting output from Bundler to OpenSfM'
data = dataset.DataSet(data_path)
data = dataset.DataSet(args.dataset)
tracks_file = data.tracks_file()
reconstruction_file = data.reconstruction_file()
io.import_bundler(data_path, bundle_file, list_file, tracks_file, reconstruction_file)
io.import_bundler(args.dataset, args.bundleout, list_file, tracks_file, reconstruction_file)
else:
print 'Cannot find list.txt or bundle.out.'
print 'Cannot find list.txt'


9 changes: 6 additions & 3 deletions opensfm/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,24 @@ def import_bundler(data_path, bundle_file, list_file, track_file, reconstruction
with open(os.path.join(data_path, 'image_list.txt'), 'w') as fout:
fout.write('\n'.join(image_list) + '\n')

reconstruction = {}
track_graph = {}
# Check for bundle_file
if not bundle_file or not os.path.isfile(bundle_file):
return None

with open(bundle_file, 'rb') as fin:
lines = fin.readlines()
offset = 1 if '#' in lines[0] else 0

# header
num_shot, num_point = map(int, lines[offset].split(' '))
offset += 1

# initialization
reconstruction = {}
reconstruction['cameras'] = {}
reconstruction['shots'] = {}
reconstruction['points'] = {}
offset += 1
track_graph = {}

# cameras
for i in xrange(num_shot):
Expand Down

0 comments on commit fdd311b

Please sign in to comment.