From 1ae797401972c3416c446cc44f720161d3679bd9 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 8 May 2023 10:43:56 -0400 Subject: [PATCH 1/2] Direct odm_orthophoto georeferencing --- SuperBuild/CMakeLists.txt | 2 +- stages/odm_orthophoto.py | 62 +++++++++++---------------------------- 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/SuperBuild/CMakeLists.txt b/SuperBuild/CMakeLists.txt index b218c19b..01773efe 100644 --- a/SuperBuild/CMakeLists.txt +++ b/SuperBuild/CMakeLists.txt @@ -242,7 +242,7 @@ externalproject_add(dem2points externalproject_add(odm_orthophoto DEPENDS opencv GIT_REPOSITORY https://github.com/OpenDroneMap/odm_orthophoto.git - GIT_TAG 314 + GIT_TAG 315 PREFIX ${SB_BINARY_DIR}/odm_orthophoto SOURCE_DIR ${SB_SOURCE_DIR}/odm_orthophoto CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SB_INSTALL_DIR} diff --git a/stages/odm_orthophoto.py b/stages/odm_orthophoto.py index 6c28c512..51ab2619 100644 --- a/stages/odm_orthophoto.py +++ b/stages/odm_orthophoto.py @@ -7,7 +7,7 @@ from opendm import context from opendm import types from opendm import gsd from opendm import orthophoto -from opendm.concurrency import get_max_memory +from opendm.concurrency import get_max_memory_mb from opendm.cutline import compute_cutline from opendm.utils import double_quote from opendm import pseudogeo @@ -42,7 +42,11 @@ class ODMOrthoPhotoStage(types.ODM_Stage): 'res': resolution, 'bands': '', 'depth_idx': '', - 'inpaint': '' + 'inpaint': '', + 'utm_offsets': '', + 'a_srs': '', + 'vars': '', + 'gdal_configs': '--config GDAL_CACHEMAX %s' % (get_max_memory_mb() * 1024 * 1024) } models = [] @@ -86,53 +90,22 @@ class ODMOrthoPhotoStage(types.ODM_Stage): kwargs['models'] = ','.join(map(double_quote, models)) + if reconstruction.is_georeferenced(): + orthophoto_vars = orthophoto.get_orthophoto_vars(args) + kwargs['utm_offsets'] = "-utm_north_offset %s -utm_east_offset %s" % (reconstruction.georef.utm_north_offset, reconstruction.georef.utm_east_offset) + kwargs['a_srs'] = "-a_srs \"%s\"" % reconstruction.georef.proj4() + kwargs['vars'] = ' '.join(['-co %s=%s' % (k, orthophoto_vars[k]) for k in orthophoto_vars]) + kwargs['ortho'] = tree.odm_orthophoto_tif # Render directly to final file + # run odm_orthophoto + log.ODM_INFO('Creating GeoTIFF') system.run('"{odm_ortho_bin}" -inputFiles {models} ' '-logFile "{log}" -outputFile "{ortho}" -resolution {res} -verbose ' - '-outputCornerFile "{corners}" {bands} {depth_idx} {inpaint}'.format(**kwargs), env_vars={'OMP_NUM_THREADS': args.max_concurrency}) + '-outputCornerFile "{corners}" {bands} {depth_idx} {inpaint} ' + '{utm_offsets} {a_srs} {vars} {gdal_configs} '.format(**kwargs), env_vars={'OMP_NUM_THREADS': args.max_concurrency}) # Create georeferenced GeoTiff - geotiffcreated = False - if reconstruction.is_georeferenced(): - ulx = uly = lrx = lry = 0.0 - with open(tree.odm_orthophoto_corners) as f: - for lineNumber, line in enumerate(f): - if lineNumber == 0: - tokens = line.split(' ') - if len(tokens) == 4: - ulx = float(tokens[0]) + \ - float(reconstruction.georef.utm_east_offset) - lry = float(tokens[1]) + \ - float(reconstruction.georef.utm_north_offset) - lrx = float(tokens[2]) + \ - float(reconstruction.georef.utm_east_offset) - uly = float(tokens[3]) + \ - float(reconstruction.georef.utm_north_offset) - log.ODM_INFO('Creating GeoTIFF') - - orthophoto_vars = orthophoto.get_orthophoto_vars(args) - - kwargs = { - 'ulx': ulx, - 'uly': uly, - 'lrx': lrx, - 'lry': lry, - 'vars': ' '.join(['-co %s=%s' % (k, orthophoto_vars[k]) for k in orthophoto_vars]), - 'proj': reconstruction.georef.proj4(), - 'input': tree.odm_orthophoto_render, - 'output': tree.odm_orthophoto_tif, - 'log': tree.odm_orthophoto_tif_log, - 'max_memory': get_max_memory(), - } - - system.run('gdal_translate -a_ullr {ulx} {uly} {lrx} {lry} ' - '{vars} ' - '-a_srs \"{proj}\" ' - '--config GDAL_CACHEMAX {max_memory}% ' - '--config GDAL_TIFF_INTERNAL_MASK YES ' - '"{input}" "{output}" > "{log}"'.format(**kwargs)) - bounds_file_path = os.path.join(tree.odm_georeferencing, 'odm_georeferenced_model.bounds.gpkg') # Cutline computation, before cropping @@ -159,8 +132,7 @@ class ODMOrthoPhotoStage(types.ODM_Stage): blend_distance=20 ) - geotiffcreated = True - if not geotiffcreated: + else: if io.file_exists(tree.odm_orthophoto_render): pseudogeo.add_pseudo_georeferencing(tree.odm_orthophoto_render) log.ODM_INFO("Renaming %s --> %s" % (tree.odm_orthophoto_render, tree.odm_orthophoto_tif)) From ffad2b02e86afef39d32fd772b3264e70e072875 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 8 May 2023 10:45:06 -0400 Subject: [PATCH 2/2] Bump version --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0aec50e6..3ad0595a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.4 +3.1.5