pull/317/head
Pau Gargallo 2016-03-01 12:01:52 +01:00
rodzic 6232338210
commit 0848ecd545
1 zmienionych plików z 26 dodań i 15 usunięć

Wyświetl plik

@ -1,3 +1,5 @@
"""Cell to run odm_slam."""
import os import os
import ecto import ecto
@ -9,16 +11,20 @@ from opendm import context
class ODMSlamCell(ecto.Cell): class ODMSlamCell(ecto.Cell):
"""Run odm_slam on a video and export to opensfm format."""
def declare_params(self, params): def declare_params(self, params):
"""Cell parameters."""
pass pass
def declare_io(self, params, inputs, outputs): def declare_io(self, params, inputs, outputs):
"""Cell inputs and outputs."""
inputs.declare("tree", "Struct with paths", []) inputs.declare("tree", "Struct with paths", [])
inputs.declare("args", "The application arguments.", {}) inputs.declare("args", "The application arguments.", {})
outputs.declare("reconstruction", "list of ODMReconstructions", []) outputs.declare("reconstruction", "list of ODMReconstructions", [])
def process(self, inputs, outputs): def process(self, inputs, outputs):
"""Run the cell."""
log.ODM_INFO('Running OMD Slam Cell') log.ODM_INFO('Running OMD Slam Cell')
# get inputs # get inputs
@ -35,7 +41,8 @@ class ODMSlamCell(ecto.Cell):
system.mkdir_p(tree.opensfm) system.mkdir_p(tree.opensfm)
system.mkdir_p(tree.pmvs) system.mkdir_p(tree.pmvs)
vocabulary = os.path.join(context.orb_slam2_path, 'Vocabulary/ORBvoc.txt') vocabulary = os.path.join(context.orb_slam2_path,
'Vocabulary/ORBvoc.txt')
orb_slam_cmd = os.path.join(context.odm_modules_path, 'odm_slam') orb_slam_cmd = os.path.join(context.odm_modules_path, 'odm_slam')
trajectory = os.path.join(tree.opensfm, 'KeyFrameTrajectory.txt') trajectory = os.path.join(tree.opensfm, 'KeyFrameTrajectory.txt')
map_points = os.path.join(tree.opensfm, 'MapPoints.txt') map_points = os.path.join(tree.opensfm, 'MapPoints.txt')
@ -62,37 +69,41 @@ class ODMSlamCell(ecto.Cell):
# convert slam to opensfm # convert slam to opensfm
system.run(' '.join([ system.run(' '.join([
'cd {} &&'.format(tree.opensfm), 'cd {} &&'.format(tree.opensfm),
'PYTHONPATH={}:{}'.format(context.pyopencv_path, context.opensfm_path), 'PYTHONPATH={}:{}'.format(context.pyopencv_path,
context.opensfm_path),
'python', 'python',
os.path.join(context.odm_modules_src_path, 'odm_slam/src/orb_slam_to_opensfm.py'), os.path.join(context.odm_modules_src_path,
'odm_slam/src/orb_slam_to_opensfm.py'),
video, video,
trajectory, trajectory,
map_points, map_points,
slam_config, slam_config,
])) ]))
else: else:
log.ODM_WARNING('Found a valid OpenSfm file in: {}'.format( log.ODM_WARNING('Found a valid OpenSfM file in: {}'.format(
tree.opensfm_reconstruction)) tree.opensfm_reconstruction))
# check if reconstruction was exported to bundler before # check if reconstruction was exported to bundler before
if not io.file_exists(tree.opensfm_bundle_list) or rerun_cell: if not io.file_exists(tree.opensfm_bundle_list) or rerun_cell:
# convert back to bundler's format # convert back to bundler's format
system.run('PYTHONPATH=%s %s/bin/export_bundler %s' % system.run(
(context.pyopencv_path, context.opensfm_path, tree.opensfm)) 'PYTHONPATH={} {}/bin/export_bundler {}'.format(
context.pyopencv_path, context.opensfm_path, tree.opensfm))
else: else:
log.ODM_WARNING('Found a valid Bundler file in: %s' % log.ODM_WARNING(
(tree.opensfm_reconstruction)) 'Found a valid Bundler file in: {}'.format(
tree.opensfm_reconstruction))
# check if reconstruction was exported to pmvs before # check if reconstruction was exported to pmvs before
if not io.file_exists(tree.pmvs_visdat) or rerun_cell: if not io.file_exists(tree.pmvs_visdat) or rerun_cell:
# run PMVS converter # run PMVS converter
system.run('PYTHONPATH=%s %s/bin/export_pmvs %s --output %s' % system.run(
(context.pyopencv_path, context.opensfm_path, tree.opensfm, tree.pmvs)) 'PYTHONPATH={} {}/bin/export_pmvs {} --output {}'.format(
context.pyopencv_path, context.opensfm_path, tree.opensfm,
tree.pmvs))
else: else:
log.ODM_WARNING('Found a valid CMVS file in: %s' % tree.pmvs_visdat) log.ODM_WARNING('Found a valid CMVS file in: {}'.format(
tree.pmvs_visdat))
log.ODM_INFO('Running OMD Slam Cell - Finished') log.ODM_INFO('Running OMD Slam Cell - Finished')
return ecto.OK if args['end_with'] != 'odm_slam' else ecto.QUIT return ecto.OK if args['end_with'] != 'odm_slam' else ecto.QUIT