OpenDroneMap-ODM/scripts/odm_app.py

187 wiersze
9.1 KiB
Python
Czysty Zwykły widok Historia

2015-11-26 12:15:02 +00:00
import ecto
2016-02-29 14:45:00 +00:00
import os
2015-11-26 12:15:02 +00:00
2015-11-27 16:52:27 +00:00
from opendm import context
from opendm import types
2016-02-29 14:45:00 +00:00
from opendm import io
from opendm import system
2015-11-27 16:52:27 +00:00
2015-11-26 12:15:02 +00:00
from dataset import ODMLoadDatasetCell
2015-11-30 15:51:29 +00:00
from opensfm import ODMOpenSfMCell
2016-02-04 10:27:45 +00:00
from odm_slam import ODMSlamCell
2015-11-30 15:51:29 +00:00
from pmvs import ODMPmvsCell
from cmvs import ODMCmvsCell
2015-11-30 15:51:29 +00:00
from odm_meshing import ODMeshingCell
2016-03-24 17:35:29 +00:00
from mvstex import ODMMvsTexCell
from odm_georeferencing import ODMGeoreferencingCell
from odm_orthophoto import ODMOrthoPhotoCell
2015-11-26 12:15:02 +00:00
2015-11-26 12:15:02 +00:00
class ODMApp(ecto.BlackBox):
"""ODMApp - a class for ODM Activities
"""
2015-11-26 12:15:02 +00:00
def __init__(self, *args, **kwargs):
ecto.BlackBox.__init__(self, *args, **kwargs)
self.tree = None
2015-11-26 12:15:02 +00:00
@staticmethod
def declare_direct_params(p):
p.declare("args", "The application arguments.", {})
@staticmethod
def declare_cells(p):
"""
Implement the virtual function from the base class
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),
'opensfm': ODMOpenSfMCell(use_exif_size=False,
feature_process_size=p.args.resize_to,
feature_min_frames=p.args.min_num_features,
processes=p.args.opensfm_processes,
matching_gps_neighbors=p.args.matcher_neighbors,
2017-08-01 19:00:13 +00:00
matching_gps_distance=p.args.matcher_distance,
fixed_camera_params=p.args.use_fixed_camera_params),
2016-05-18 11:09:36 +00:00
'slam': ODMSlamCell(),
'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,
2016-12-14 18:30:44 +00:00
min_imgs=p.args.pmvs_min_images,
cores=p.args.pmvs_num_cores),
2016-12-14 18:30:44 +00:00
'meshing': ODMeshingCell(max_vertex=p.args.mesh_size,
oct_tree=p.args.mesh_octree_depth,
samples=p.args.mesh_samples,
solver=p.args.mesh_solver_divide,
remove_outliers=p.args.mesh_remove_outliers,
wlop_iterations=p.args.mesh_wlop_iterations,
2016-12-11 22:16:11 +00:00
verbose=p.args.verbose),
2016-12-14 18:30:44 +00:00
'texturing': ODMMvsTexCell(data_term=p.args.texturing_data_term,
outlier_rem_type=p.args.texturing_outlier_removal_type,
skip_vis_test=p.args.texturing_skip_visibility_test,
skip_glob_seam_leveling=p.args.texturing_skip_global_seam_leveling,
skip_loc_seam_leveling=p.args.texturing_skip_local_seam_leveling,
skip_hole_fill=p.args.texturing_skip_hole_filling,
2017-02-22 17:41:24 +00:00
keep_unseen_faces=p.args.texturing_keep_unseen_faces,
tone_mapping=p.args.texturing_tone_mapping),
'georeferencing': ODMGeoreferencingCell(img_size=p.args.resize_to,
gcp_file=p.args.gcp,
use_exif=p.args.use_exif,
2017-04-06 13:06:09 +00:00
dem=p.args.dem,
2017-04-06 19:37:13 +00:00
sample_radius=p.args.dem_sample_radius,
gdal_res=p.args.dem_resolution,
gdal_radius=p.args.dem_radius,
2016-12-11 22:16:11 +00:00
verbose=p.args.verbose),
'orthophoto': ODMOrthoPhotoCell(resolution=p.args.orthophoto_resolution,
2017-03-10 21:09:55 +00:00
t_srs=p.args.orthophoto_target_srs,
no_tiled=p.args.orthophoto_no_tiled,
compress=p.args.orthophoto_compression,
bigtiff=p.args.orthophoto_bigtiff,
2017-03-31 18:53:47 +00:00
build_overviews=p.args.build_overviews,
verbose=p.args.verbose)
}
return cells
2015-11-26 12:15:02 +00:00
def configure(self, p, _i, _o):
tree = types.ODM_Tree(p.args.project_path, p.args.images)
self.tree = ecto.Constant(value=tree)
2015-11-27 16:52:27 +00:00
2016-02-29 14:45:00 +00:00
# TODO(dakota) put this somewhere better maybe
if p.args.time and io.file_exists(tree.benchmarking):
2016-02-29 14:45:00 +00:00
# Delete the previously made file
os.remove(tree.benchmarking)
with open(tree.benchmarking, 'a') as b:
b.write('ODM Benchmarking file created %s\nNumber of Cores: %s\n\n' % (system.now(), context.num_cores))
2016-02-29 14:45:00 +00:00
def connections(self, p):
if p.args.video:
return self.slam_connections(_p)
2016-02-04 10:27:45 +00:00
# define initial task
# TODO: What is this?
# initial_task = p.args['start_with']
# initial_task_id = config.processopts.index(initial_task)
2015-11-26 12:15:02 +00:00
# define the connections like you would for the plasm
# load the dataset
connections = [self.tree[:] >> self.dataset['tree']]
2015-12-11 21:26:39 +00:00
# run opensfm with images from load dataset
connections += [self.tree[:] >> self.opensfm['tree'],
self.args[:] >> self.opensfm['args'],
2017-08-24 19:19:51 +00:00
self.dataset['photos'] >> self.opensfm['photos']]
if not p.args.use_pmvs:
# create odm mesh from opensfm point cloud
connections += [self.tree[:] >> self.meshing['tree'],
self.args[:] >> self.meshing['args'],
self.opensfm['reconstruction'] >> self.meshing['reconstruction']]
else:
# run cmvs
connections += [self.tree[:] >> self.cmvs['tree'],
self.args[:] >> self.cmvs['args'],
self.opensfm['reconstruction'] >> self.cmvs['reconstruction']]
# run pmvs
connections += [self.tree[:] >> self.pmvs['tree'],
self.args[:] >> self.pmvs['args'],
self.cmvs['reconstruction'] >> self.pmvs['reconstruction']]
# create odm mesh from pmvs point cloud
connections += [self.tree[:] >> self.meshing['tree'],
self.args[:] >> self.meshing['args'],
self.pmvs['reconstruction'] >> self.meshing['reconstruction']]
2015-12-11 21:26:39 +00:00
# create odm texture
connections += [self.tree[:] >> self.texturing['tree'],
self.args[:] >> self.texturing['args'],
self.meshing['reconstruction'] >> self.texturing['reconstruction']]
2015-12-11 21:26:39 +00:00
# create odm georeference
connections += [self.tree[:] >> self.georeferencing['tree'],
self.args[:] >> self.georeferencing['args'],
2017-08-24 19:19:51 +00:00
self.dataset['photos'] >> self.georeferencing['photos'],
self.texturing['reconstruction'] >> self.georeferencing['reconstruction']]
# create odm orthophoto
connections += [self.tree[:] >> self.orthophoto['tree'],
self.args[:] >> self.orthophoto['args'],
self.georeferencing['reconstruction'] >> self.orthophoto['reconstruction']]
2015-12-30 14:36:56 +00:00
return connections
def slam_connections(self, p):
"""Get connections used when running from video instead of images."""
connections = []
# run slam cell
connections += [self.tree[:] >> self.slam['tree'],
self.args[:] >> self.slam['args']]
# run cmvs
connections += [self.tree[:] >> self.cmvs['tree'],
self.args[:] >> self.cmvs['args'],
self.slam['reconstruction'] >> self.cmvs['reconstruction']]
2015-12-11 21:26:39 +00:00
# run pmvs
connections += [self.tree[:] >> self.pmvs['tree'],
self.args[:] >> self.pmvs['args'],
self.cmvs['reconstruction'] >> self.pmvs['reconstruction']]
2015-12-11 21:26:39 +00:00
# create odm mesh
connections += [self.tree[:] >> self.meshing['tree'],
self.args[:] >> self.meshing['args'],
self.pmvs['reconstruction'] >> self.meshing['reconstruction']]
2015-12-11 21:26:39 +00:00
# create odm texture
connections += [self.tree[:] >> self.texturing['tree'],
self.args[:] >> self.texturing['args'],
self.meshing['reconstruction'] >> self.texturing['reconstruction']]
2015-12-30 14:36:56 +00:00
return connections