diff --git a/opendm/cutline.py b/opendm/cutline.py index b0d1f801..4d21694b 100644 --- a/opendm/cutline.py +++ b/opendm/cutline.py @@ -3,16 +3,28 @@ import shutil from opendm import log from opendm import io from opendm import concurrency - +from opendm import get_image_size +import math def compute_cutline(orthophoto_file, crop_area_file, destination, max_concurrency=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") + 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)) + number_lines = int(max(8, math.ceil(min(ortho_width, ortho_height) / 256.0))) + except get_image_size.UnknownImageFormat: + log.ODM_DEBUG("Cannot compute orthophoto dimensions, setting arbitrary number of lines.") + number_lines = 32 + + log.ODM_DEBUG("Number of lines: %s" % number_lines) + gctx = grass.create_context({'auto_cleanup' : False}) gctx.add_param('orthophoto_file', orthophoto_file) gctx.add_param('crop_area_file', crop_area_file) + gctx.add_param('number_lines', number_lines) gctx.add_param('max_concurrency', max_concurrency) gctx.add_param('memory', int(concurrency.get_max_memory_mb(300))) gctx.set_location(orthophoto_file) diff --git a/opendm/grass/compute_cutline.grass b/opendm/grass/compute_cutline.grass index d7bdb6fd..299411c9 100644 --- a/opendm/grass/compute_cutline.grass +++ b/opendm/grass/compute_cutline.grass @@ -1,5 +1,6 @@ # orthophoto_file: input GeoTIFF raster file # crop_area_file: input vector polygon file delimiting the safe area for processing +# number_lines: number of cutlines on the smallest side of the orthophoto for computing the final cutline # max_concurrency: maximum number of parallel processes to use # memory: maximum MB of memory to use # ------ @@ -14,7 +15,7 @@ v.in.ogr input="${crop_area_file}" output=crop_area --overwrite g.region vector=crop_area # Generate cutlines -i.cutlines.py --overwrite input=ortho output=cutline number_lines=16 edge_detection=zc no_edge_friction=20 lane_border_multiplier=1000000 tile_width=1024 tile_height=1024 overlap=20 processes=${max_concurrency} memory=${memory} +i.cutlinesmod.py --overwrite input=ortho output=cutline number_lines=${number_lines} edge_detection=zc no_edge_friction=20 lane_border_multiplier=1000000 tile_width=1024 tile_height=1024 overlap=20 processes=${max_concurrency} memory=${memory} #v.out.ogr input=cutline output="cutline_raw.gpkg" format=GPKG diff --git a/scripts/grass_addons/i.cutlines.py b/scripts/grass_addons/i.cutlinesmod.py similarity index 98% rename from scripts/grass_addons/i.cutlines.py rename to scripts/grass_addons/i.cutlinesmod.py index 4817a3f6..00215529 100755 --- a/scripts/grass_addons/i.cutlines.py +++ b/scripts/grass_addons/i.cutlinesmod.py @@ -2,8 +2,9 @@ ############################################################################ # -# MODULE: i.cutlines -# AUTHOR(S): Moritz Lennert, with help of Stefanos Georganos +# MODULE: i.cutlines2 +# AUTHOR(S): Moritz Lennert, with help of Stefanos Georganos, modified by +# Piero Toffanin # # PURPOSE: Create tiles the borders of which do not cut across semantically # meaningful objects @@ -301,10 +302,10 @@ def main(): if nsrange > ewrange: hnumber_lines = number_lines - vnumber_lines = int(number_lines * (ewrange / nsrange)) + vnumber_lines = int(number_lines * (nsrange / ewrange)) else: vnumber_lines = number_lines - hnumber_lines = int(number_lines * (nsrange / ewrange)) + hnumber_lines = int(number_lines * (ewrange / nsrange)) # Create the lines in horizonal direction nsstep = float(region.n - region.s - region.nsres) / hnumber_lines