Scaled orthos for cutline computation

Former-commit-id: 64b974afd9
pull/1161/head
Piero Toffanin 2019-05-30 08:53:25 -04:00
rodzic 1d52b058f7
commit 27deb2a13c
2 zmienionych plików z 23 dodań i 2 usunięć

Wyświetl plik

@ -7,7 +7,7 @@ from opendm import get_image_size
from opendm import system
import math
def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrency=1, tmpdir=None):
def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrency=1, tmpdir=None, scale=1):
if io.file_exists(orthophoto_file) and io.file_exists(crop_area_file):
from opendm.grass_engine import grass
log.ODM_DEBUG("Computing cutline")
@ -15,6 +15,26 @@ def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrenc
if tmpdir and not io.dir_exists(tmpdir):
system.mkdir_p(tmpdir)
scale = max(0.0001, min(1, scale))
scaled_orthophoto = None
if scale < 1:
log.ODM_DEBUG("Scaling orthophoto to %s%% to compute cutline" % (scale * 100))
scaled_orthophoto = os.path.join(tmpdir, os.path.basename(io.related_file_path(orthophoto_file, postfix=".scaled")))
# Scale orthophoto before computing cutline
system.run("gdal_translate -outsize {}% 0 "
"-co NUM_THREADS={} "
"--config GDAL_CACHEMAX {}% "
"{} {}".format(
scale * 100,
max_concurrency,
concurrency.get_max_memory(),
orthophoto_file,
scaled_orthophoto
))
orthophoto_file = scaled_orthophoto
try:
ortho_width,ortho_height = get_image_size.get_image_size(orthophoto_file)
log.ODM_DEBUG("Orthophoto dimensions are %sx%s" % (ortho_width, ortho_height))

Wyświetl plik

@ -116,7 +116,8 @@ class ODMOrthoPhotoStage(types.ODM_Stage):
bounds_file_path,
os.path.join(tree.odm_orthophoto, "cutline.gpkg"),
args.max_concurrency,
tmpdir=os.path.join(tree.odm_orthophoto, "grass_cutline_tmpdir"))
tmpdir=os.path.join(tree.odm_orthophoto, "grass_cutline_tmpdir"),
scale=0.25)
if args.crop > 0:
Cropper.crop(bounds_file_path, tree.odm_orthophoto_tif, orthophoto_vars)