From 72d3a48b60064d40213f56dfe117e845e28b066a Mon Sep 17 00:00:00 2001 From: edgarriba Date: Wed, 2 Dec 2015 11:16:30 +0000 Subject: [PATCH] fix resizing issue with file metadata --- opendm/io.py | 5 ++++- scripts/dataset.py | 12 +++++++++--- scripts/resize.py | 11 ++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/opendm/io.py b/opendm/io.py index 7556223e..b97c95eb 100644 --- a/opendm/io.py +++ b/opendm/io.py @@ -19,4 +19,7 @@ def join_paths(path1, path2): return os.path.join(path1, path2) def file_exists(path_file): - return os.path.isfile(path_file) \ No newline at end of file + return os.path.isfile(path_file) + +def dir_exists(dirname): + return os.path.isdir(dirname) \ No newline at end of file diff --git a/scripts/dataset.py b/scripts/dataset.py index c74cfb8e..4a365d58 100644 --- a/scripts/dataset.py +++ b/scripts/dataset.py @@ -26,7 +26,14 @@ class ODMLoadDatasetCell(ecto.Cell): # get parameters args = self.inputs.args project_path = io.absolute_path_file(args['project_path']) - images_dir = io.join_paths(project_path, 'images') + images_dir = io.join_paths(project_path, 'images_resize') + + # check if we rerun cell or not + rerun_cell = args['run_only'] is not None \ + and args['run_only'] == 'resize' + + if not io.dir_exists(images_dir) or rerun_cell: + images_dir = io.join_paths(project_path, 'images') log.ODM_DEBUG('Loading dataset from: %s' % images_dir) @@ -38,9 +45,8 @@ class ODMLoadDatasetCell(ecto.Cell): files = [f for f in files if supported_extension(f)] if files: - photos = [] - # create ODMPhoto list + photos = [] for f in files: path_file = io.join_paths(images_dir, f) photos.append(types.ODMPhoto(path_file, args)) diff --git a/scripts/resize.py b/scripts/resize.py index d28c7265..4e638921 100644 --- a/scripts/resize.py +++ b/scripts/resize.py @@ -64,6 +64,9 @@ class ODMResizeCell(ecto.Cell): new_meta.read() # copy metadata old_meta.copy(new_meta) + # update metadata size + new_meta['Exif.Photo.PixelXDimension'].value = img_r.shape[0] + new_meta['Exif.Photo.PixelYDimension'].value = img_r.shape[1] new_meta.write() # update photos array with new values photo.path_file = new_path_file @@ -72,10 +75,12 @@ class ODMResizeCell(ecto.Cell): photo.update_focal() # log message - log.ODM_DEBUG('Resized %s | dimensions: %s to %s' % \ - (photo.filename, img_r.shape, args['resize_to'])) + log.ODM_DEBUG('Resized %s | dimensions: %s' % \ + (photo.filename, img_r.shape)) else: - log.ODM_WARNING('Already resized %s' % photo.filename) + # log message + log.ODM_WARNING('Already resized %s | dimensions: %s x %s' % \ + (photo.filename, photo.width, photo.height)) log.ODM_INFO('Resized %s images' % len(photos))