From 4445c85db1f0cd9e9045ae1da27ce9bf47754766 Mon Sep 17 00:00:00 2001 From: Dakota Benjamin Date: Fri, 9 Dec 2016 09:51:25 -0500 Subject: [PATCH] Add option for automatic project setup using -i Former-commit-id: 715f45d8280f48c516dabaa1c8cc260c41f85d10 --- opendm/config.py | 4 ++++ opendm/types.py | 6 +++++- scripts/dataset.py | 35 +++++++++++++++++++++++------------ scripts/odm_app.py | 2 +- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/opendm/config.py b/opendm/config.py index e8d84589..00ab85b7 100644 --- a/opendm/config.py +++ b/opendm/config.py @@ -16,6 +16,10 @@ parser = argparse.ArgumentParser(description='OpenDroneMap') def config(): + parser.add_argument('--images', '-i', + metavar='', + help='Path to input images'), + parser.add_argument('--project-path', metavar='', help='Path to the project to process') diff --git a/opendm/types.py b/opendm/types.py index edf524c3..2857c242 100644 --- a/opendm/types.py +++ b/opendm/types.py @@ -331,9 +331,13 @@ class ODM_GeoRef(object): class ODM_Tree(object): - def __init__(self, root_path): + def __init__(self, root_path, images_path): # root path to the project self.root_path = io.absolute_path_file(root_path) + if not images_path: + self.input_images = io.join_paths(self.root_path, 'images') + else: + self.input_images = io.absolute_path_file(images_path) # modules paths diff --git a/scripts/dataset.py b/scripts/dataset.py index 6705b5c8..e3e553a4 100644 --- a/scripts/dataset.py +++ b/scripts/dataset.py @@ -7,6 +7,8 @@ from opendm import context from opendm import io from opendm import types from opendm import log +from opendm import system +from shutil import copyfile def make_odm_photo(force_focal, force_ccd, path_file): @@ -28,32 +30,41 @@ class ODMLoadDatasetCell(ecto.Cell): outputs.declare("photos", "list of ODMPhotos", []) def process(self, inputs, outputs): - # check if the extension is sopported + # check if the extension is supported def supported_extension(file_name): (pathfn, ext) = os.path.splitext(file_name) return ext.lower() in context.supported_extensions + # Get supported images from dir + def get_images(in_dir): + # filter images for its extension type + log.ODM_DEBUG(in_dir) + return [f for f in io.get_files_list(in_dir) if supported_extension(f)] + log.ODM_INFO('Running ODM Load Dataset Cell') # get inputs tree = self.inputs.tree - # set images directory - images_dir = tree.dataset_resize + # get images directory + input_dir = tree.input_images + images_dir = tree.dataset_raw + resize_dir = tree.dataset_resize - if not io.dir_exists(images_dir): - images_dir = tree.dataset_raw + # Check first if a project already exists. This is a mediocre way to check, by checking the resize dir + if io.dir_exists(resize_dir): + log.ODM_DEBUG("resize dir: %s" % resize_dir) + images_dir = resize_dir + # if first time running, create project directory and copy images over to project/images + else: if not io.dir_exists(images_dir): - log.ODM_ERROR("You must put your pictures into an directory") - return ecto.QUIT + log.ODM_INFO("Project directory %s doesn't exist. Creating it now. " % images_dir) + system.mkdir_p(images_dir) + copied = [copyfile(io.join_paths(input_dir, f), io.join_paths(images_dir, f)) for f in get_images(input_dir)] log.ODM_DEBUG('Loading dataset from: %s' % images_dir) - # find files in the given directory - files = io.get_files_list(images_dir) - - # filter images for its extension type - files = [f for f in files if supported_extension(f)] + files = get_images(images_dir) if files: # create ODMPhoto list diff --git a/scripts/odm_app.py b/scripts/odm_app.py index f5abef41..d3f341bd 100644 --- a/scripts/odm_app.py +++ b/scripts/odm_app.py @@ -78,7 +78,7 @@ class ODMApp(ecto.BlackBox): return cells def configure(self, p, _i, _o): - tree = types.ODM_Tree(p.args.project_path) + tree = types.ODM_Tree(p.args.project_path, p.args.images) self.tree = ecto.Constant(value=tree) # TODO(dakota) put this somewhere better maybe