OpenDroneMap-ODM/scripts/dataset.py

87 wiersze
3.0 KiB
Python
Czysty Zwykły widok Historia

2015-11-26 12:15:02 +00:00
import os
import ecto
from functools import partial
from multiprocessing import Pool
2015-11-26 12:15:02 +00:00
from opendm import context
from opendm import io
from opendm import types
from opendm import log
from opendm import system
from shutil import copyfile
2015-11-26 12:15:02 +00:00
def make_odm_photo(force_focal, force_ccd, path_file):
return types.ODM_Photo(path_file,
force_focal,
force_ccd)
2015-11-27 10:00:43 +00:00
class ODMLoadDatasetCell(ecto.Cell):
def declare_params(self, params):
2015-12-10 12:35:52 +00:00
params.declare("force_focal", 'Override the focal length information for the '
'images', None)
2016-10-18 15:37:37 +00:00
params.declare("force_ccd", 'Override the ccd width information for the '
'images', None)
2015-11-26 12:15:02 +00:00
def declare_io(self, params, inputs, outputs):
inputs.declare("tree", "Struct with paths", [])
2016-10-18 15:37:37 +00:00
outputs.declare("photos", "list of ODMPhotos", [])
2015-11-26 12:15:02 +00:00
def process(self, inputs, outputs):
# check if the extension is supported
2015-11-26 12:15:02 +00:00
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)]
2015-11-26 12:15:02 +00:00
log.ODM_INFO('Running ODM Load Dataset Cell')
# get inputs
tree = self.inputs.tree
# get images directory
input_dir = tree.input_images
images_dir = tree.dataset_raw
resize_dir = tree.dataset_resize
2015-12-02 11:16:30 +00:00
# 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_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)]
2015-11-26 12:15:02 +00:00
log.ODM_DEBUG('Loading dataset from: %s' % images_dir)
files = get_images(images_dir)
2015-11-26 12:15:02 +00:00
if files:
2015-11-26 12:15:02 +00:00
# create ODMPhoto list
path_files = [io.join_paths(images_dir, f) for f in files]
photos = Pool().map(
partial(make_odm_photo, self.params.force_focal, self.params.force_ccd),
path_files
)
2015-11-27 10:00:43 +00:00
log.ODM_INFO('Found %s usable images' % len(photos))
else:
log.ODM_ERROR('Not enough supported images in %s' % images_dir)
return ecto.QUIT
2015-11-26 12:15:02 +00:00
# append photos to cell output
outputs.photos = photos
log.ODM_INFO('Running ODM Load Dataset Cell - Finished')
return ecto.OK