Added GSD cap on resolution params

pull/889/head
Piero Toffanin 2018-08-08 15:41:08 -04:00
rodzic 7cfcbe823b
commit d5abc19b36
4 zmienionych plików z 33 dodań i 5 usunięć

Wyświetl plik

@ -1,7 +1,31 @@
import os
import json
import numpy as np
import functools
from opendm import log
def cap_resolution(resolution, reconstruction_json):
"""
:param resolution resolution in cm / pixel
:param reconstruction_json path to OpenSfM's reconstruction.json
:return The max value between resolution and the GSD computed from the reconstruction.
If a GSD cannot be computed, it just returns resolution. Units are in cm / pixel.
"""
gsd = opensfm_reconstruction_average_gsd(reconstruction_json)
if gsd is not None:
log.ODM_INFO('Ground Sampling Distance: {} cm / pixel'.format(round(gsd, 2))
if gsd > resolution:
log.ODM_WARNING('Maximum resolution set to GSD (requested resolution was {})'.format(round(resolution, 2)))
return gsd
else:
return resolution
else:
log.ODM_WARNING('Cannot calculate GSD, using requested resolution of {}'.format(round(resolution, 2))
return resolution
@functools.lru_cache(maxsize=None, typed=False)
def opensfm_reconstruction_average_gsd(reconstruction_json):
"""
Computes the average Ground Sampling Distance of an OpenSfM reconstruction.

Wyświetl plik

@ -6,6 +6,7 @@ from opendm import log
from opendm import system
from opendm import context
from opendm import types
from opendm import gsd
from opendm.dem import commands
from opendm.cropper import Cropper
@ -90,8 +91,9 @@ class ODMDEMCell(ecto.Cell):
products = []
if args.dsm: products.append('dsm')
if args.dtm: products.append('dtm')
radius_steps = [(float(args.dem_resolution) / 100.0) / 2.0]
resolution = gsd.cap_resolution(args.dem_resolution, tree.opensfm_reconstruction)
radius_steps = [(resolution / 100.0) / 2.0]
for _ in range(args.dem_gapfill_steps - 1):
radius_steps.append(radius_steps[-1] * 2) # 2 is arbitrary, maybe there's a better value?
@ -102,7 +104,7 @@ class ODMDEMCell(ecto.Cell):
radius=map(str, radius_steps),
gapfill=True,
outdir=odm_dem_root,
resolution=float(args.dem_resolution) / 100.0,
resolution=resolution / 100.0,
maxsd=args.dem_maxsd,
maxangle=args.dem_maxangle,
decimation=args.dem_decimation,

Wyświetl plik

@ -5,6 +5,7 @@ from opendm import io
from opendm import system
from opendm import context
from opendm import mesh
from opendm import gsd
class ODMeshingCell(ecto.Cell):
@ -78,7 +79,7 @@ class ODMeshingCell(ecto.Cell):
if not io.file_exists(tree.odm_25dmesh) or rerun_cell:
log.ODM_DEBUG('Writing ODM 2.5D Mesh file in: %s' % tree.odm_25dmesh)
dsm_resolution = float(args.orthophoto_resolution) / 100.0
dsm_resolution = gsd.cap_resolution(args.orthophoto_resolution, tree.opensfm_reconstruction) / 100.0
# Create reference DSM at half ortho resolution
dsm_resolution *= 2

Wyświetl plik

@ -6,6 +6,7 @@ from opendm import log
from opendm import system
from opendm import context
from opendm import types
from opendm import gsd
from opendm.cropper import Cropper
@ -56,7 +57,7 @@ class ODMOrthoPhotoCell(ecto.Cell):
'log': tree.odm_orthophoto_log,
'ortho': tree.odm_orthophoto_file,
'corners': tree.odm_orthophoto_corners,
'res': 1.0 / (float(self.params.resolution) / 100.0),
'res': 1.0 / (gsd.cap_resolution(self.params.resolution, tree.reconstruction_json) / 100.0),
'verbose': verbose
}