| 21 | |
| 22 | # $ mkdir $DATASET_PATH/dense |
| 23 | def run_colmap(basedir, match_type): |
| 24 | |
| 25 | logfile_name = os.path.join(basedir, 'colmap_output.txt') |
| 26 | logfile = open(logfile_name, 'w') |
| 27 | |
| 28 | feature_extractor_args = [ |
| 29 | 'colmap', 'feature_extractor', |
| 30 | '--database_path', os.path.join(basedir, 'database.db'), |
| 31 | '--image_path', os.path.join(basedir, 'images'), |
| 32 | '--ImageReader.single_camera', '1', |
| 33 | # '--SiftExtraction.use_gpu', '0', |
| 34 | ] |
| 35 | feat_output = ( subprocess.check_output(feature_extractor_args, universal_newlines=True) ) |
| 36 | logfile.write(feat_output) |
| 37 | print('Features extracted') |
| 38 | |
| 39 | exhaustive_matcher_args = [ |
| 40 | 'colmap', match_type, |
| 41 | '--database_path', os.path.join(basedir, 'database.db'), |
| 42 | ] |
| 43 | |
| 44 | match_output = ( subprocess.check_output(exhaustive_matcher_args, universal_newlines=True) ) |
| 45 | logfile.write(match_output) |
| 46 | print('Features matched') |
| 47 | |
| 48 | p = os.path.join(basedir, 'sparse') |
| 49 | if not os.path.exists(p): |
| 50 | os.makedirs(p) |
| 51 | |
| 52 | # mapper_args = [ |
| 53 | # 'colmap', 'mapper', |
| 54 | # '--database_path', os.path.join(basedir, 'database.db'), |
| 55 | # '--image_path', os.path.join(basedir, 'images'), |
| 56 | # '--output_path', os.path.join(basedir, 'sparse'), |
| 57 | # '--Mapper.num_threads', '16', |
| 58 | # '--Mapper.init_min_tri_angle', '4', |
| 59 | # ] |
| 60 | mapper_args = [ |
| 61 | 'colmap', 'mapper', |
| 62 | '--database_path', os.path.join(basedir, 'database.db'), |
| 63 | '--image_path', os.path.join(basedir, 'images'), |
| 64 | '--output_path', os.path.join(basedir, 'sparse'), # --export_path changed to --output_path in colmap 3.6 |
| 65 | '--Mapper.num_threads', '16', |
| 66 | '--Mapper.init_min_tri_angle', '4', |
| 67 | '--Mapper.multiple_models', '0', |
| 68 | '--Mapper.extract_colors', '0', |
| 69 | ] |
| 70 | |
| 71 | map_output = ( subprocess.check_output(mapper_args, universal_newlines=True) ) |
| 72 | logfile.write(map_output) |
| 73 | logfile.close() |
| 74 | print('Sparse map created') |
| 75 | |
| 76 | print( 'Finished running COLMAP, see {} for logs'.format(logfile_name) ) |
| 77 | |
| 78 | |