Use Namespace instead of Dict for argparse

pull/347/head
Dakota Benjamin 2016-03-08 13:26:58 -05:00
rodzic 1d1459090c
commit 97bccd3cb4
11 zmienionych plików z 351 dodań i 336 usunięć

Wyświetl plik

@ -13,6 +13,9 @@ class RerunFrom(argparse.Action):
parser = argparse.ArgumentParser(description='OpenDroneMap')
def config():
parser.add_argument('--project-path',
metavar='<string>',
help='Path to the project to process')
@ -235,6 +238,7 @@ parser.add_argument('--mvs_texturing-keepUnseenFaces',
'Default: %(default)s'))
# Old odm_texturing arguments
parser.add_argument('--odm_texturing-textureResolution',
metavar='<positive integer>',
default=4096,
@ -248,6 +252,7 @@ parser.add_argument('--odm_texturing-textureWithSize',
type=int,
help=('The resolution to rescale the images performing '
'the texturing. Default: %(default)s'))
# End of old odm_texturing arguments
parser.add_argument('--odm_georeferencing-gcpFile',
@ -283,4 +288,4 @@ parser.add_argument('--time',
help='Generates a benchmark file with runtime info\n'
'Default: %(default)s')
args = vars(parser.parse_args())
return parser.parse_args()

6
run.py
Wyświetl plik

@ -20,13 +20,15 @@ if __name__ == '__main__':
log.ODM_INFO('Initializing OpenDroneMap app - %s' % system.now())
args = config.config()
# Force to provide the images path
if config.args.get('project_path') is None:
if args.project_path is None:
usage()
# create an instance of my App BlackBox
# internally configure all tasks
app = ODMApp(args=config.args)
app = ODMApp(args=args)
# create a plasm that only contains the BlackBox
plasm = ecto.Plasm()

Wyświetl plik

@ -25,21 +25,21 @@ class ODMCmvsCell(ecto.Cell):
# Benchmarking
start_time = system.now_raw()
log.ODM_INFO('Running OMD CMVS Cell')
log.ODM_INFO('Running ODM CMVS Cell')
# get inputs
args = self.inputs.args
tree = self.inputs.tree
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'cmvs') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'cmvs' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'cmvs') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'cmvs' in args.rerun_from)
if not io.file_exists(tree.pmvs_bundle) or rerun_cell:
log.ODM_DEBUG('Writting CMVS vis in: %s' % tree.pmvs_bundle)
log.ODM_DEBUG('Writing CMVS vis in: %s' % tree.pmvs_bundle)
# copy bundle file to pmvs dir
from shutil import copyfile
@ -59,8 +59,8 @@ class ODMCmvsCell(ecto.Cell):
log.ODM_WARNING('Found a valid CMVS file in: %s' %
tree.pmvs_bundle)
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'CMVS')
log.ODM_INFO('Running OMD CMVS Cell - Finished')
return ecto.OK if args['end_with'] != 'cmvs' else ecto.QUIT
log.ODM_INFO('Running ODM CMVS Cell - Finished')
return ecto.OK if args.end_with != 'cmvs' else ecto.QUIT

Wyświetl plik

@ -38,52 +38,54 @@ class ODMApp(ecto.BlackBox):
Only cells from which something is forwarded have to be declared
"""
cells = {'args': ecto.Constant(value=p.args),
'dataset': ODMLoadDatasetCell(force_focal=p.args['force_focal'],
force_ccd=p.args['force_ccd']),
'resize': ODMResizeCell(resize_to=p.args['resize_to']),
'dataset': ODMLoadDatasetCell(force_focal=p.args.force_focal,
force_ccd=p.args.force_ccd),
'resize': ODMResizeCell(resize_to=p.args.resize_to),
'opensfm': ODMOpenSfMCell(use_exif_size=False,
feature_process_size=p.args['resize_to'],
feature_min_frames=p.args['min_num_features'],
feature_process_size=p.args.resize_to,
feature_min_frames=p.args.min_num_features,
processes=context.num_cores,
matching_gps_neighbors=p.args['matcher_neighbors'],
matching_gps_distance=p.args['matcher_distance']),
'cmvs': ODMCmvsCell(max_images=p.args['cmvs_maxImages']),
'pmvs': ODMPmvsCell(level=p.args['pmvs_level'],
csize=p.args['pmvs_csize'],
thresh=p.args['pmvs_threshold'],
wsize=p.args['pmvs_wsize'],
min_imgs=p.args['pmvs_minImageNum'],
cores=p.args['pmvs_num_cores']),
'meshing': ODMeshingCell(max_vertex=p.args['odm_meshing_maxVertexCount'],
oct_tree=p.args['odm_meshing_octreeDepth'],
samples=p.args['odm_meshing_samplesPerNode'],
solver=p.args['odm_meshing_solverDivide']),
'texturing': ODMMvsTexCell(data_term=p.args['mvs_texturing_dataTerm'],
outlier_rem_type=p.args['mvs_texturing_outlierRemovalType'],
skip_vis_test=p.args['mvs_texturing_skipGeometricVisibilityTest'],
skip_glob_seam_leveling=p.args['mvs_texturing_skipGlobalSeamLeveling'],
skip_loc_seam_leveling=p.args['mvs_texturing_skipLocalSeamLeveling'],
skip_hole_fill=p.args['mvs_texturing_skipHoleFilling'],
keep_unseen_faces=p.args['mvs_texturing_keepUnseenFaces']),
'texturing': ODMMvsTexCell(data_term=p.args.mvs_texturing_dataTerm,
outlier_rem_type=p.args.mvs_texturing_outlierRemovalType,
skip_vis_test=p.args.mvs_texturing_skipGeometricVisibilityTest,
skip_glob_seam_leveling=p.args.mvs_texturing_skipGlobalSeamLeveling,
skip_loc_seam_leveling=p.args.mvs_texturing_skipLocalSeamLeveling,
skip_hole_fill=p.args.mvs_texturing_skipHoleFilling,
keep_unseen_faces=p.args.mvs_texturing_keepUnseenFaces),
# Old odm_texturing
# 'texturing': ODMTexturingCell(resize=p.args['resize_to'],
# resolution=p.args['odm_texturing_textureResolution'],
# size=p.args['odm_texturing_textureWithSize']),
'georeferencing': ODMGeoreferencingCell(img_size=p.args['resize_to'],
gcp_file=p.args['odm_georeferencing_gcpFile'],
use_gcp=p.args['odm_georeferencing_useGcp']),
'orthophoto': ODMOrthoPhotoCell(resolution=p.args['odm_orthophoto_resolution'])
matching_gps_neighbors=p.args.matcher_neighbors,
matching_gps_distance=p.args.matcher_distance),
'cmvs': ODMCmvsCell(max_images=p.args.cmvs_maxImages),
'pmvs': ODMPmvsCell(level=p.args.pmvs_level,
csize=p.args.pmvs_csize,
thresh=p.args.pmvs_threshold,
wsize=p.args.pmvs_wsize,
min_imgs=p.args.pmvs_minImageNum,
cores=p.args.pmvs_num_cores),
'meshing': ODMeshingCell(max_vertex=p.args.odm_meshing_maxVertexCount,
oct_tree=p.args.odm_meshing_octreeDepth,
samples=p.args.odm_meshing_samplesPerNode,
solver=p.args.odm_meshing_solverDivide),
'texturing': ODMTexturingCell(resize=p.args.resize_to,
resolution=p.args.odm_texturing_textureResolution,
size=p.args.odm_texturing_textureWithSize),
'georeferencing': ODMGeoreferencingCell(img_size=p.args.resize_to,
gcp_file=p.args.odm_georeferencing_gcpFile,
use_gcp=p.args.odm_georeferencing_useGcp),
'orthophoto': ODMOrthoPhotoCell(resolution=p.args.odm_orthophoto_resolution)
}
return cells
def configure(self, p, _i, _o):
tree = types.ODM_Tree(p.args['project_path'])
tree = types.ODM_Tree(p.args.project_path)
self.tree = ecto.Constant(value=tree)
# TODO(dakota) put this somewhere better maybe
if config.args.get('time') and io.file_exists(tree.benchmarking):
if p.args.time and io.file_exists(tree.benchmarking):
# Delete the previously made file
os.remove(tree.benchmarking)
with open(tree.benchmarking, 'a') as b:

Wyświetl plik

@ -28,7 +28,7 @@ class ODMGeoreferencingCell(ecto.Cell):
# Benchmarking
start_time = system.now_raw()
log.ODM_INFO('Running OMD Georeferencing Cell')
log.ODM_INFO('Running ODM Georeferencing Cell')
# get inputs
args = self.inputs.args
@ -68,11 +68,11 @@ class ODMGeoreferencingCell(ecto.Cell):
return ecto.QUIT
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'odm_georeferencing') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'odm_georeferencing' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'odm_georeferencing') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'odm_georeferencing' in args.rerun_from)
if not io.file_exists(tree.odm_georeferencing_model_obj_geo) or \
not io.file_exists(tree.odm_georeferencing_model_ply_geo) or rerun_cell:
@ -141,8 +141,8 @@ class ODMGeoreferencingCell(ecto.Cell):
log.ODM_WARNING('Found a valid georeferenced model in: %s'
% tree.odm_georeferencing_model_ply_geo)
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'Georeferencing')
log.ODM_INFO('Running OMD Georeferencing Cell - Finished')
return ecto.OK if args['end_with'] != 'odm_georeferencing' else ecto.QUIT
log.ODM_INFO('Running ODM Georeferencing Cell - Finished')
return ecto.OK if args.end_with != 'odm_georeferencing' else ecto.QUIT

Wyświetl plik

@ -31,7 +31,7 @@ class ODMeshingCell(ecto.Cell):
# Benchmarking
start_time = system.now_raw()
log.ODM_INFO('Running OMD Meshing Cell')
log.ODM_INFO('Running ODM Meshing Cell')
# get inputs
args = self.inputs.args
@ -41,11 +41,11 @@ class ODMeshingCell(ecto.Cell):
system.mkdir_p(tree.odm_meshing)
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'odm_meshing') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'odm_meshing' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'odm_meshing') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'odm_meshing' in args.rerun_from)
if not io.file_exists(tree.odm_mesh) or rerun_cell:
log.ODM_DEBUG('Writting ODM Mesh file in: %s' % tree.odm_mesh)
@ -70,8 +70,8 @@ class ODMeshingCell(ecto.Cell):
log.ODM_WARNING('Found a valid ODM Mesh file in: %s' %
tree.odm_mesh)
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'Meshing')
log.ODM_INFO('Running OMD Meshing Cell - Finished')
return ecto.OK if args['end_with'] != 'odm_meshing' else ecto.QUIT
log.ODM_INFO('Running ODM Meshing Cell - Finished')
return ecto.OK if args.end_with != 'odm_meshing' else ecto.QUIT

Wyświetl plik

@ -31,11 +31,11 @@ class ODMOrthoPhotoCell(ecto.Cell):
system.mkdir_p(tree.odm_orthophoto)
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'odm_orthophoto') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'odm_orthophoto' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'odm_orthophoto') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'odm_orthophoto' in args.rerun_from)
if not io.file_exists(tree.odm_orthophoto_file) or rerun_cell:
@ -98,8 +98,8 @@ class ODMOrthoPhotoCell(ecto.Cell):
else:
log.ODM_WARNING('Found a valid orthophoto in: %s' % tree.odm_orthophoto_file)
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'Orthophoto')
log.ODM_INFO('Running OMD OrthoPhoto Cell - Finished')
return ecto.OK if args['end_with'] != 'odm_orthophoto' else ecto.QUIT
log.ODM_INFO('Running ODM OrthoPhoto Cell - Finished')
return ecto.OK if args.end_with != 'odm_orthophoto' else ecto.QUIT

Wyświetl plik

@ -25,7 +25,7 @@ class ODMTexturingCell(ecto.Cell):
# Benchmarking
start_time = system.now_raw()
log.ODM_INFO('Running OMD Texturing Cell')
log.ODM_INFO('Running ODM Texturing Cell')
# get inputs
args = self.inputs.args
@ -35,11 +35,11 @@ class ODMTexturingCell(ecto.Cell):
system.mkdir_p(tree.odm_texturing)
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'odm_texturing') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'odm_texturing' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'odm_texturing') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'odm_texturing' in args.rerun_from)
if not io.file_exists(tree.odm_textured_model_obj) or rerun_cell:
log.ODM_DEBUG('Writing ODM Textured file in: %s'
@ -69,8 +69,8 @@ class ODMTexturingCell(ecto.Cell):
log.ODM_WARNING('Found a valid ODM Texture file in: %s'
% tree.odm_textured_model_obj)
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'Texturing')
log.ODM_INFO('Running OMD Texturing Cell - Finished')
return ecto.OK if args['end_with'] != 'odm_texturing' else ecto.QUIT
log.ODM_INFO('Running ODM Texturing Cell - Finished')
return ecto.OK if args.end_with != 'odm_texturing' else ecto.QUIT

Wyświetl plik

@ -26,7 +26,7 @@ class ODMOpenSfMCell(ecto.Cell):
# Benchmarking
start_time = system.now_raw()
log.ODM_INFO('Running OMD OpenSfm Cell')
log.ODM_INFO('Running ODM OpenSfM Cell')
# get inputs
tree = self.inputs.tree
@ -34,7 +34,7 @@ class ODMOpenSfMCell(ecto.Cell):
photos = self.inputs.photos
if not photos:
log.ODM_ERROR('Not enough photos in photos array to start OpenSfm')
log.ODM_ERROR('Not enough photos in photos array to start OpenSfM')
return ecto.QUIT
# create working directories
@ -42,11 +42,11 @@ class ODMOpenSfMCell(ecto.Cell):
system.mkdir_p(tree.pmvs)
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'opensfm') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'opensfm' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'opensfm') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'opensfm' in args.rerun_from)
# check if reconstruction was done before
@ -78,7 +78,7 @@ class ODMOpenSfMCell(ecto.Cell):
system.run('PYTHONPATH=%s %s/bin/run_all %s' %
(context.pyopencv_path, context.opensfm_path, tree.opensfm))
else:
log.ODM_WARNING('Found a valid OpenSfm file in: %s' %
log.ODM_WARNING('Found a valid OpenSfM file in: %s' %
tree.opensfm_reconstruction)
# check if reconstruction was exported to bundler before
@ -100,8 +100,8 @@ class ODMOpenSfMCell(ecto.Cell):
else:
log.ODM_WARNING('Found a valid CMVS file in: %s' % tree.pmvs_visdat)
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'OpenSfM')
log.ODM_INFO('Running OMD OpenSfm Cell - Finished')
return ecto.OK if args['end_with'] != 'opensfm' else ecto.QUIT
log.ODM_INFO('Running ODM OpenSfM Cell - Finished')
return ecto.OK if args.end_with != 'opensfm' else ecto.QUIT

Wyświetl plik

@ -44,11 +44,11 @@ class ODMPmvsCell(ecto.Cell):
tree = self.inputs.tree
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'pmvs') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'pmvs' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'pmvs') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'pmvs' in args.rerun_from)
if not io.file_exists(tree.pmvs_model) or rerun_cell:
log.ODM_DEBUG('Creating dense pointcloud in: %s' % tree.pmvs_model)
@ -75,8 +75,8 @@ class ODMPmvsCell(ecto.Cell):
else:
log.ODM_WARNING('Found a valid PMVS file in %s' % tree.pmvs_model)
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'PMVS')
log.ODM_INFO('Running OMD PMVS Cell - Finished')
return ecto.OK if args['end_with'] != 'pmvs' else ecto.QUIT
log.ODM_INFO('Running ODM PMVS Cell - Finished')
return ecto.OK if args.end_with != 'pmvs' else ecto.QUIT

Wyświetl plik

@ -34,17 +34,21 @@ class ODMResizeCell(ecto.Cell):
log.ODM_ERROR('Not enough photos in photos to resize')
return ecto.QUIT
if self.params.resize_to <= 0:
log.ODM_ERROR('Resize parameter must be greater than 0')
return ecto.QUIT
# create working directory
system.mkdir_p(tree.dataset_resize)
log.ODM_DEBUG('Resizing dataset to: %s' % tree.dataset_resize)
# check if we rerun cell or not
rerun_cell = (args['rerun'] is not None and
args['rerun'] == 'resize') or \
(args['rerun_all']) or \
(args['rerun_from'] is not None and
'resize' in args['rerun_from'])
rerun_cell = (args.rerun is not None and
args.rerun == 'resize') or \
(args.rerun_all) or \
(args.rerun_from is not None and
'resize' in args.rerun_from)
# loop over photos
for photo in photos:
@ -60,6 +64,8 @@ class ODMResizeCell(ecto.Cell):
img = cv2.imread(path_file)
# compute new size
max_side = max(img.shape[0], img.shape[1])
if max_side <= self.params.resize_to:
log.ODM_WARNING('Resize Parameter is greater than the largest side of the image')
ratio = float(self.params.resize_to) / float(max_side)
img_r = cv2.resize(img, None, fx=ratio, fy=ratio)
# write image with opencv
@ -94,8 +100,8 @@ class ODMResizeCell(ecto.Cell):
# append photos to cell output
self.outputs.photos = photos
if args['time']:
if args.time:
system.benchmark(start_time, tree.benchmarking, 'Resizing')
log.ODM_INFO('Running ODM Resize Cell - Finished')
return ecto.OK if args['end_with'] != 'resize' else ecto.QUIT
return ecto.OK if args.end_with != 'resize' else ecto.QUIT