OpenDroneMap-ODM/scripts/mve.py

105 wiersze
4.0 KiB
Python
Czysty Zwykły widok Historia

import ecto, shutil, os, glob
from opendm import log
from opendm import io
from opendm import system
from opendm import context
from opendm import point_cloud
2018-12-02 17:45:26 +00:00
class ODMMveCell(ecto.Cell):
def declare_io(self, params, inputs, outputs):
inputs.declare("tree", "Struct with paths", [])
inputs.declare("args", "The application arguments.", {})
inputs.declare("reconstruction", "ODMReconstruction", [])
outputs.declare("reconstruction", "list of ODMReconstructions", [])
def process(self, inputs, outputs):
# Benchmarking
start_time = system.now_raw()
2018-12-02 17:45:26 +00:00
log.ODM_INFO('Running MVE Cell')
# get inputs
tree = inputs.tree
args = inputs.args
reconstruction = inputs.reconstruction
photos = reconstruction.photos
if not photos:
2018-12-02 17:45:26 +00:00
log.ODM_ERROR('Not enough photos in photos array to start MVE')
return ecto.QUIT
# check if we rerun cell or not
rerun_cell = (args.rerun is not None and
2018-12-02 17:45:26 +00:00
args.rerun == 'mve') or \
(args.rerun_all) or \
(args.rerun_from is not None and
2018-12-02 17:45:26 +00:00
'mve' in args.rerun_from)
# check if reconstruction was done before
2018-12-02 17:45:26 +00:00
if not io.file_exists(tree.mve_model) or rerun_cell:
2018-10-29 15:39:37 +00:00
# cleanup if a rerun
if io.dir_exists(tree.mve_path) and rerun_cell:
shutil.rmtree(tree.mve_path)
2018-06-30 23:36:53 +00:00
# make bundle directory
if not io.file_exists(tree.mve_bundle):
2018-10-29 15:39:37 +00:00
system.mkdir_p(tree.mve_path)
system.mkdir_p(io.join_paths(tree.mve_path, 'bundle'))
io.copy(tree.opensfm_image_list, tree.mve_image_list)
io.copy(tree.opensfm_bundle, tree.mve_bundle)
2018-07-02 19:21:30 +00:00
# mve makescene wants the output directory
# to not exists before executing it (otherwise it
# will prompt the user for confirmation)
2018-12-02 17:45:26 +00:00
if io.dir_exists(tree.mve):
shutil.rmtree(tree.mve)
2018-07-02 19:21:30 +00:00
2018-06-30 23:36:53 +00:00
# run mve makescene
2018-07-01 22:49:53 +00:00
if not io.dir_exists(tree.mve_views):
2018-12-02 17:45:26 +00:00
system.run('%s %s %s' % (context.makescene_path, tree.mve_path, tree.mve))
2018-06-30 23:36:53 +00:00
dmrecon_config = [
"--max-pixels=%s" % int(args.depthmap_resolution * args.depthmap_resolution),
# "-s%s" % args.mve_output_scale,
"--progress=silent",
"--force",
]
# Run MVE's dmrecon
system.run('%s %s %s' % (context.dmrecon_path, ' '.join(dmrecon_config), tree.mve))
2019-02-19 20:08:38 +00:00
scene2pset_config = [
"-F1",
"--with-conf"
]
2019-02-19 20:08:38 +00:00
# run scene2pset
system.run('%s %s "%s" "%s"' % (context.scene2pset_path, ' '.join(scene2pset_config), tree.mve, tree.mve_model))
# run pdal
# system.run('pdal translate -i {} '
# ' -o {} '
# ' -f range --filters.range.limits="confidence[0.25:1]'.format(tree.mve_model, tree.mve_model_output))
# find and rename the output file for simplicity
2018-12-02 17:45:26 +00:00
mve_files = glob.glob(os.path.join(tree.mve, 'mve-*'))
mve_files.sort(key=os.path.getmtime) # sort by last modified date
if len(mve_files) > 0:
old_file = mve_files[-1]
if not (io.rename_file(old_file, tree.mve_model)):
log.ODM_WARNING("File %s does not exist, cannot be renamed. " % old_file)
else:
2018-12-02 17:45:26 +00:00
log.ODM_WARNING("Cannot find a valid point cloud (mve-XX.ply) in %s. Check the console output for errors." % tree.mve)
else:
2018-12-02 17:45:26 +00:00
log.ODM_WARNING('Found a valid MVE reconstruction file in: %s' %
tree.mve_model)
outputs.reconstruction = reconstruction
if args.time:
2018-12-02 17:45:26 +00:00
system.benchmark(start_time, tree.benchmarking, 'MVE')
2018-12-02 17:45:26 +00:00
log.ODM_INFO('Running ODM MVE Cell - Finished')
return ecto.OK if args.end_with != 'mve' else ecto.QUIT