From 1d46daad3da04887f9176b5209d01c4d8a661283 Mon Sep 17 00:00:00 2001 From: Blake McConnell Date: Fri, 6 Dec 2019 17:45:53 -0800 Subject: [PATCH] add matching mode flag in imgs2poses this feature fixes a bug where linear videa images cause pose saving to fail. now that different feature matching techniques can be specified, we can pass 'sequential_matcher' which results in success. future work should accomodate other feature matching techniques --- imgs2poses.py | 9 ++++++++- llff/poses/colmap_wrapper.py | 7 ++++--- llff/poses/pose_utils.py | 7 +++++-- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/imgs2poses.py b/imgs2poses.py index 4c40845..8a47960 100644 --- a/imgs2poses.py +++ b/imgs2poses.py @@ -3,9 +3,16 @@ import argparse parser = argparse.ArgumentParser() +parser.add_argument('--match_type', type=str, + default='exhaustive_matcher', help='type of matcher used. Valid options: \ + exhaustive_matcher sequential_matcher. Other matchers not supported at this time') parser.add_argument('scenedir', type=str, help='input scene directory') args = parser.parse_args() +if args.match_type != 'exhaustive_matcher' and args.match_type != 'sequential_matcher': + print('ERROR: matcher type ' + args.match_type + ' is not valid. Aborting') + sys.exit() + if __name__=='__main__': - gen_poses(args.scenedir) \ No newline at end of file + gen_poses(args.scenedir, args.match_type) \ No newline at end of file diff --git a/llff/poses/colmap_wrapper.py b/llff/poses/colmap_wrapper.py index 1e3aa59..6c91bb6 100644 --- a/llff/poses/colmap_wrapper.py +++ b/llff/poses/colmap_wrapper.py @@ -20,7 +20,7 @@ # --output_path $DATASET_PATH/sparse # $ mkdir $DATASET_PATH/dense -def run_colmap(basedir): +def run_colmap(basedir, match_type): logfile_name = os.path.join(basedir, 'colmap_output.txt') logfile = open(logfile_name, 'w') @@ -35,11 +35,12 @@ def run_colmap(basedir): feat_output = ( subprocess.check_output(feature_extractor_args, universal_newlines=True) ) logfile.write(feat_output) print('Features extracted') - + exhaustive_matcher_args = [ - 'colmap', 'exhaustive_matcher', + 'colmap', match_type, '--database_path', os.path.join(basedir, 'database.db'), ] + match_output = ( subprocess.check_output(exhaustive_matcher_args, universal_newlines=True) ) logfile.write(match_output) print('Features matched') diff --git a/llff/poses/pose_utils.py b/llff/poses/pose_utils.py index 24e264f..3cc4eb5 100644 --- a/llff/poses/pose_utils.py +++ b/llff/poses/pose_utils.py @@ -60,6 +60,9 @@ def save_poses(basedir, poses, pts3d, perm): pts_arr.append(pts3d[k].xyz) cams = [0] * poses.shape[-1] for ind in pts3d[k].image_ids: + if len(cams) < ind - 1: + print('ERROR: the correct camera poses for current points cannot be accessed') + return cams[ind-1] = 1 vis_arr.append(cams) @@ -253,7 +256,7 @@ def imread(f): -def gen_poses(basedir, factors=None): +def gen_poses(basedir, match_type, factors=None): files_needed = ['{}.bin'.format(f) for f in ['cameras', 'images', 'points3D']] if os.path.exists(os.path.join(basedir, 'sparse/0')): @@ -262,7 +265,7 @@ def gen_poses(basedir, factors=None): files_had = [] if not all([f in files_had for f in files_needed]): print( 'Need to run COLMAP' ) - run_colmap(basedir) + run_colmap(basedir, match_type) else: print('Don\'t need to run COLMAP')