Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the COLMAP .bin files to the top level SfM directory #76

Merged
merged 5 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hloc/pipelines/4Seasons/localize.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
ffile = extract_features.main(fconf, seq_images, output_dir)
mfile = match_features.main(mconf, loc_pairs, fconf['output'], output_dir)
localize_sfm.main(
ref_sfm / 'model', query_list, loc_pairs, ffile, mfile, results_path)
ref_sfm, query_list, loc_pairs, ffile, mfile, results_path)

# Convert the absolute poses to relative poses with the reference frames.
submission_dir.mkdir(exist_ok=True)
Expand Down
4 changes: 2 additions & 2 deletions hloc/pipelines/7Scenes/create_gt_sfm.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def correct_sfm_with_gt_depth(sfm_path, depth_folder_path, output_path):
outputs = Path('outputs/7Scenes')

for scene in SCENES:
sfm_path = outputs / scene / 'sfm_superpoint+superglue/model'
sfm_path = outputs / scene / 'sfm_superpoint+superglue'
depth_path = dataset / f'depth/7scenes_{scene}/train/depth'
output_path = outputs / scene / 'sfm_superpoint+superglue+depth/model'
output_path = outputs / scene / 'sfm_superpoint+superglue+depth'
correct_sfm_with_gt_depth(sfm_path, depth_path, output_path)
5 changes: 2 additions & 3 deletions hloc/pipelines/7Scenes/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,14 @@ def run_scene(images, gt_dir, retrieval, outputs, results, num_covis,
if use_dense_depth:
assert depth_dir is not None
ref_sfm_fix = outputs / 'sfm_superpoint+superglue+depth'
correct_sfm_with_gt_depth(
ref_sfm / 'model', depth_dir, ref_sfm_fix / 'model')
correct_sfm_with_gt_depth(ref_sfm, depth_dir, ref_sfm_fix)
ref_sfm = ref_sfm_fix

loc_matches = match_features.main(
matcher_conf, retrieval, feature_conf['output'], outputs)

localize_sfm.main(
ref_sfm / 'model',
ref_sfm,
query_list,
retrieval,
features,
Expand Down
4 changes: 2 additions & 2 deletions hloc/pipelines/Aachen/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
global_descriptors = extract_features.main(retrieval_conf, images, outputs)
pairs_from_retrieval.main(
global_descriptors, loc_pairs, args.num_loc,
query_prefix='query', db_model=reference_sfm / 'model')
query_prefix='query', db_model=reference_sfm)
loc_matches = match_features.main(
matcher_conf, loc_pairs, feature_conf['output'], outputs)

localize_sfm.main(
reference_sfm / 'model',
reference_sfm,
dataset / 'queries/*_time_queries_with_intrinsics.txt',
loc_pairs,
features,
Expand Down
4 changes: 2 additions & 2 deletions hloc/pipelines/Aachen_v1_1/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
global_descriptors = extract_features.main(retrieval_conf, images, outputs)
pairs_from_retrieval.main(
global_descriptors, loc_pairs, args.num_loc,
query_prefix='query', db_model=reference_sfm / 'model')
query_prefix='query', db_model=reference_sfm)
loc_matches = match_features.main(
matcher_conf, loc_pairs, feature_conf['output'], outputs)

localize_sfm.main(
reference_sfm / 'model',
reference_sfm,
dataset / 'queries/*_time_queries_with_intrinsics.txt',
loc_pairs,
features,
Expand Down
4 changes: 2 additions & 2 deletions hloc/pipelines/CMU/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ def run_slice(slice_, root, outputs, num_covis, num_loc):
retrieval_conf, query_images, outputs)
pairs_from_retrieval.main(
global_descriptors, loc_pairs, num_loc,
query_list=query_list, db_model=ref_sfm / 'model')
query_list=query_list, db_model=ref_sfm)

features = extract_features.main(
feature_conf, query_images, outputs, as_half=True)
loc_matches = match_features.main(
matcher_conf, loc_pairs, feature_conf['output'], outputs)

localize_sfm.main(
ref_sfm / 'model',
ref_sfm,
dataset / 'queries/*_time_queries_with_intrinsics.txt',
loc_pairs,
features,
Expand Down
2 changes: 1 addition & 1 deletion hloc/pipelines/Cambridge/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def run_scene(images, gt_dir, outputs, results, num_covis, num_loc):
matcher_conf, loc_pairs, feature_conf['output'], outputs)

localize_sfm.main(
ref_sfm / 'model',
ref_sfm,
query_list,
loc_pairs,
features,
Expand Down
4 changes: 2 additions & 2 deletions hloc/pipelines/RobotCar/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ def generate_query_list(dataset, image_dir, path):
# TODO: do per location and per camera
pairs_from_retrieval.main(
global_descriptors, loc_pairs, args.num_loc,
query_prefix='query', db_model=reference_sfm / 'model')
query_prefix='query', db_model=reference_sfm)
loc_matches = match_features.main(
matcher_conf, loc_pairs, feature_conf['output'], outputs)

localize_sfm.main(
reference_sfm / 'model',
reference_sfm,
Path(str(query_list).format(condition='*')),
loc_pairs,
features,
Expand Down
18 changes: 10 additions & 8 deletions hloc/reconstruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,24 @@ def get_image_ids(database_path):
return images


def run_reconstruction(colmap_path, model_path, database_path, image_dir,
def run_reconstruction(colmap_path, sfm_dir, database_path, image_dir,
min_num_matches=None):
logging.info('Running the 3D reconstruction...')
model_path.mkdir(exist_ok=True)
models_path = sfm_dir / 'models'
models_path.mkdir(exist_ok=True, parents=True)

cmd = [
str(colmap_path), 'mapper',
'--database_path', str(database_path),
'--image_path', str(image_dir),
'--output_path', str(model_path),
'--output_path', str(models_path),
'--Mapper.num_threads', str(min(multiprocessing.cpu_count(), 16))]
if min_num_matches:
cmd += ['--Mapper.min_num_matches', str(min_num_matches)]
logging.info(' '.join(cmd))
subprocess.run(cmd, check=True)

models = list(model_path.iterdir())
models = list(models_path.iterdir())
if len(models) == 0:
logging.error('Could not reconstruct any model!')
return False
Expand All @@ -91,7 +92,7 @@ def run_reconstruction(colmap_path, model_path, database_path, image_dir,
largest_model_num_images = num_images
assert largest_model_num_images > 0
logging.info(f'Largest model is #{largest_model.name} '
'with {largest_model_num_images} images.')
f'with {largest_model_num_images} images.')

stats_raw = subprocess.check_output(
[str(colmap_path), 'model_analyzer',
Expand All @@ -112,6 +113,9 @@ def run_reconstruction(colmap_path, model_path, database_path, image_dir,
elif stat.startswith("Mean reprojection error"):
stats['mean_reproj_error'] = float(stat.split()[-1][:-2])

for filename in ['images.bin', 'cameras.bin', 'points3D.bin']:
shutil.move(str(largest_model / filename), str(sfm_dir))

return stats


Expand All @@ -126,8 +130,6 @@ def main(sfm_dir, image_dir, pairs, features, matches,

sfm_dir.mkdir(parents=True, exist_ok=True)
database = sfm_dir / 'database.db'
models = sfm_dir / 'models'
models.mkdir(exist_ok=True)

create_empty_db(database)
import_images(
Expand All @@ -139,7 +141,7 @@ def main(sfm_dir, image_dir, pairs, features, matches,
if not skip_geometric_verification:
geometric_verification(colmap_path, database, pairs)
stats = run_reconstruction(
colmap_path, models, database, image_dir, min_num_matches)
colmap_path, sfm_dir, database, image_dir, min_num_matches)
stats['num_input_images'] = len(image_ids)
logging.info(f'Statistics:\n{pprint.pformat(stats)}')

Expand Down
4 changes: 1 addition & 3 deletions hloc/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ def main(sfm_dir, reference_sfm_model, image_dir, pairs, features, matches,

sfm_dir.mkdir(parents=True, exist_ok=True)
database = sfm_dir / 'database.db'
model = sfm_dir / 'model'
model.mkdir(exist_ok=True)
empty_model = sfm_dir / 'empty'

create_empty_model(reference_sfm_model, empty_model)
Expand All @@ -180,7 +178,7 @@ def main(sfm_dir, reference_sfm_model, image_dir, pairs, features, matches,
if not skip_geometric_verification:
geometric_verification(colmap_path, database, pairs)
stats = run_triangulation(
colmap_path, model, database, image_dir, empty_model)
colmap_path, sfm_dir, database, image_dir, empty_model)

logging.info(f'Statistics:\n{pprint.pformat(stats)}')
shutil.rmtree(empty_model)
Expand Down
10 changes: 5 additions & 5 deletions pipeline_Aachen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
"outputs": [],
"source": [
"localize_sfm.main(\n",
" reference_sfm / 'model',\n",
" reference_sfm,\n",
" dataset / 'queries/*_time_queries_with_intrinsics.txt',\n",
" loc_pairs,\n",
" feature_path,\n",
Expand Down Expand Up @@ -239,7 +239,7 @@
}
],
"source": [
"visualization.visualize_sfm_2d(reference_sfm / 'model', images, n=1, color_by='track_length')"
"visualization.visualize_sfm_2d(reference_sfm, images, n=1, color_by='track_length')"
]
},
{
Expand All @@ -255,7 +255,7 @@
"metadata": {},
"outputs": [],
"source": [
"visualization.visualize_sfm_2d(reference_sfm / 'model', images, n=1, color_by='visibility')"
"visualization.visualize_sfm_2d(reference_sfm, images, n=1, color_by='visibility')"
]
},
{
Expand All @@ -282,7 +282,7 @@
}
],
"source": [
"visualization.visualize_sfm_2d(reference_sfm / 'model', images, n=1, color_by='depth')"
"visualization.visualize_sfm_2d(reference_sfm, images, n=1, color_by='depth')"
]
},
{
Expand Down Expand Up @@ -311,7 +311,7 @@
],
"source": [
"visualization.visualize_loc(\n",
" results, images, reference_sfm / 'model', n=1, top_k_db=1, prefix='query/night', seed=2)"
" results, images, reference_sfm, n=1, top_k_db=1, prefix='query/night', seed=2)"
]
}
],
Expand Down
8 changes: 4 additions & 4 deletions pipeline_SfM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
"metadata": {},
"outputs": [],
"source": [
"visualization.visualize_sfm_2d(sfm_dir / 'models/0', images, color_by='visibility', n=5)"
"visualization.visualize_sfm_2d(sfm_dir, images, color_by='visibility', n=5)"
]
},
{
Expand All @@ -132,7 +132,7 @@
"metadata": {},
"outputs": [],
"source": [
"visualization.visualize_sfm_2d(sfm_dir / 'models/0', images, color_by='track_length', n=5)"
"visualization.visualize_sfm_2d(sfm_dir, images, color_by='track_length', n=5)"
]
},
{
Expand All @@ -141,7 +141,7 @@
"metadata": {},
"outputs": [],
"source": [
"visualization.visualize_sfm_2d(sfm_dir / 'models/0', images, color_by='depth', n=5)"
"visualization.visualize_sfm_2d(sfm_dir, images, color_by='depth', n=5)"
]
}
],
Expand All @@ -166,4 +166,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}