2021-06-09 15:46:56 +00:00
import os , traceback , sys
2015-11-26 12:15:02 +00:00
2015-11-27 16:52:27 +00:00
from opendm import context
2015-12-10 11:01:41 +00:00
from opendm import types
2016-02-29 14:45:00 +00:00
from opendm import io
2016-02-29 14:47:54 +00:00
from opendm import system
2019-04-22 19:14:39 +00:00
from opendm import log
2020-09-09 16:10:24 +00:00
from stages . dataset import ODMLoadDatasetStage
from stages . run_opensfm import ODMOpenSfMStage
2020-10-27 21:10:10 +00:00
from stages . openmvs import ODMOpenMVSStage
2020-09-09 16:10:24 +00:00
from stages . odm_meshing import ODMeshingStage
from stages . mvstex import ODMMvsTexStage
from stages . odm_georeferencing import ODMGeoreferencingStage
from stages . odm_orthophoto import ODMOrthoPhotoStage
from stages . odm_dem import ODMDEMStage
from stages . odm_filterpoints import ODMFilterPoints
from stages . splitmerge import ODMSplitStage , ODMMergeStage
2015-11-26 12:15:02 +00:00
2020-09-09 16:10:24 +00:00
from stages . odm_report import ODMReport
2021-07-30 20:07:34 +00:00
from stages . odm_postprocess import ODMPostProcess
2016-02-26 18:50:12 +00:00
2019-04-22 19:14:39 +00:00
class ODMApp :
def __init__ ( self , args ) :
2015-11-26 12:15:02 +00:00
"""
2019-04-22 19:14:39 +00:00
Initializes the application and defines the ODM application pipeline stages
2015-11-26 12:15:02 +00:00
"""
2021-06-09 16:28:44 +00:00
json_log_paths = [ os . path . join ( args . project_path , " log.json " ) ]
2023-11-08 16:07:20 +00:00
2021-06-09 16:28:44 +00:00
if args . copy_to :
json_log_paths . append ( args . copy_to )
log . logger . init_json_output ( json_log_paths , args )
2021-06-08 18:25:38 +00:00
2022-11-14 16:07:51 +00:00
dataset = ODMLoadDatasetStage ( ' dataset ' , args , progress = 5.0 )
2019-05-15 21:04:09 +00:00
split = ODMSplitStage ( ' split ' , args , progress = 75.0 )
merge = ODMMergeStage ( ' merge ' , args , progress = 100.0 )
opensfm = ODMOpenSfMStage ( ' opensfm ' , args , progress = 25.0 )
2020-10-27 21:10:10 +00:00
openmvs = ODMOpenMVSStage ( ' openmvs ' , args , progress = 50.0 )
2019-05-15 21:04:09 +00:00
filterpoints = ODMFilterPoints ( ' odm_filterpoints ' , args , progress = 52.0 )
meshing = ODMeshingStage ( ' odm_meshing ' , args , progress = 60.0 ,
2019-04-22 19:14:39 +00:00
max_vertex = args . mesh_size ,
2021-07-03 12:46:49 +00:00
oct_tree = max ( 1 , min ( 14 , args . mesh_octree_depth ) ) ,
2020-12-19 17:29:00 +00:00
samples = 1.0 ,
point_weight = 4.0 ,
2022-11-14 16:07:51 +00:00
max_concurrency = args . max_concurrency )
2022-07-27 17:58:35 +00:00
texturing = ODMMvsTexStage ( ' mvs_texturing ' , args , progress = 70.0 )
2019-05-15 21:04:09 +00:00
georeferencing = ODMGeoreferencingStage ( ' odm_georeferencing ' , args , progress = 80.0 ,
2022-11-14 16:07:51 +00:00
gcp_file = args . gcp )
2019-05-15 21:04:09 +00:00
dem = ODMDEMStage ( ' odm_dem ' , args , progress = 90.0 ,
2022-11-14 16:07:51 +00:00
max_concurrency = args . max_concurrency )
2020-05-15 18:36:46 +00:00
orthophoto = ODMOrthoPhotoStage ( ' odm_orthophoto ' , args , progress = 98.0 )
2021-07-30 20:07:34 +00:00
report = ODMReport ( ' odm_report ' , args , progress = 99.0 )
postprocess = ODMPostProcess ( ' odm_postprocess ' , args , progress = 100.0 )
2019-04-25 00:01:44 +00:00
2019-06-21 18:47:00 +00:00
# Normal pipeline
self . first_stage = dataset
2019-04-22 19:14:39 +00:00
2019-06-21 18:47:00 +00:00
dataset . connect ( split ) \
. connect ( merge ) \
. connect ( opensfm )
2019-04-22 19:14:39 +00:00
2021-01-13 22:22:44 +00:00
if args . fast_orthophoto :
2019-06-21 18:47:00 +00:00
opensfm . connect ( filterpoints )
2016-09-30 13:08:56 +00:00
else :
2020-10-27 21:10:10 +00:00
opensfm . connect ( openmvs ) \
. connect ( filterpoints )
2019-06-21 18:47:00 +00:00
filterpoints \
. connect ( meshing ) \
. connect ( texturing ) \
. connect ( georeferencing ) \
. connect ( dem ) \
2020-05-15 18:36:46 +00:00
. connect ( orthophoto ) \
2021-07-30 20:07:34 +00:00
. connect ( report ) \
. connect ( postprocess )
2019-06-21 18:47:00 +00:00
2019-04-22 19:14:39 +00:00
def execute ( self ) :
2021-04-05 13:50:04 +00:00
try :
self . first_stage . run ( )
2021-06-09 15:46:56 +00:00
log . logger . log_json_success ( )
2021-04-05 13:50:04 +00:00
return 0
except system . SubprocessException as e :
print ( " " )
print ( " ===== Dumping Info for Geeks (developers need this to fix bugs) ===== " )
print ( str ( e ) )
2021-06-09 15:46:56 +00:00
stack_trace = traceback . format_exc ( )
print ( stack_trace )
2021-04-05 13:50:04 +00:00
print ( " ===== Done, human-readable information to follow... ===== " )
print ( " " )
code = e . errorCode
2021-06-09 15:46:56 +00:00
log . logger . log_json_stage_error ( str ( e ) , code , stack_trace )
2021-04-05 13:50:04 +00:00
2021-10-15 16:30:32 +00:00
if code == 139 or code == 134 or code == 1 or code == 3221225477 :
2021-04-05 13:50:04 +00:00
# Segfault
2021-10-06 14:55:24 +00:00
log . ODM_ERROR ( " Uh oh! Processing stopped because of strange values in the reconstruction. This is often a sign that the input data has some issues or the software cannot deal with it. Have you followed best practices for data acquisition? See https://docs.opendronemap.org/flying/ " )
2022-01-12 17:05:36 +00:00
elif code == 137 or code == 3221226505 :
2021-04-05 20:50:16 +00:00
log . ODM_ERROR ( " Whoops! You ran out of memory! Add more RAM to your computer, if you ' re using docker configure it to use more memory, for WSL2 make use of .wslconfig (https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconfig), resize your images, lower the quality settings or process the images using a cloud provider (e.g. https://webodm.net). " )
2021-04-05 13:50:04 +00:00
elif code == 132 :
log . ODM_ERROR ( " Oh no! It looks like your CPU is not supported (is it fairly old?). You can still use ODM, but you will need to build your own docker image. See https://github.com/OpenDroneMap/ODM#build-from-source " )
elif code == 3 :
log . ODM_ERROR ( " ODM can ' t find a program that is required for processing to run! Did you do a custom build of ODM? (cool!) Make sure that all programs required by ODM are in the right place and are built correctly. " )
2021-04-05 14:06:40 +00:00
else :
2021-04-05 13:50:04 +00:00
log . ODM_ERROR ( " The program exited with a strange error code. Please report it at https://community.opendronemap.org " )
2021-04-05 14:06:40 +00:00
2021-04-05 13:50:04 +00:00
# TODO: more?
2021-04-05 20:50:16 +00:00
return code
2021-06-09 15:46:56 +00:00
except system . ExitException as e :
log . ODM_ERROR ( str ( e ) )
log . logger . log_json_stage_error ( str ( e ) , 1 , traceback . format_exc ( ) )
sys . exit ( 1 )
except Exception as e :
log . logger . log_json_stage_error ( str ( e ) , 1 , traceback . format_exc ( ) )
raise e
2021-06-08 18:25:38 +00:00
finally :
log . logger . close ( )