Number of lines computation

Former-commit-id: 5a8284c5cc
pull/1161/head
Piero Toffanin 2019-04-28 09:49:46 -04:00
rodzic 00aa23ecd1
commit 96b6d1593d
3 zmienionych plików z 20 dodań i 6 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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

Wyświetl plik

@ -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