kopia lustrzana https://github.com/OpenDroneMap/ODM
Some optimization, exception handling
rodzic
e5bd090ba5
commit
4137f20bd9
|
@ -11,6 +11,7 @@ from opendm.utils import double_quote
|
||||||
from opendm import log
|
from opendm import log
|
||||||
from opendm import io
|
from opendm import io
|
||||||
from opendm import system
|
from opendm import system
|
||||||
|
from opendm.concurrency import get_max_memory
|
||||||
|
|
||||||
def get_point_cloud_crs(file):
|
def get_point_cloud_crs(file):
|
||||||
pipeline = pdal.Pipeline(json.dumps([ file ]))
|
pipeline = pdal.Pipeline(json.dumps([ file ]))
|
||||||
|
@ -34,16 +35,18 @@ def reproject_point_cloud(file, out_srs):
|
||||||
return out_file
|
return out_file
|
||||||
|
|
||||||
def reproject_raster(file, out_srs):
|
def reproject_raster(file, out_srs):
|
||||||
out_file = io.related_file_path(file, postfix="_reprojected")
|
out_file = io.related_file_path(file, postfix="_reprojected_tmp")
|
||||||
kwargs = {
|
kwargs = {
|
||||||
'input': double_quote(file),
|
'input': double_quote(file),
|
||||||
'output': double_quote(out_file),
|
'output': double_quote(out_file),
|
||||||
'out_srs': out_srs,
|
'out_srs': out_srs,
|
||||||
|
'max_memory': get_max_memory()
|
||||||
}
|
}
|
||||||
system.run('gdalwarp '
|
system.run('gdalwarp '
|
||||||
'-t_srs {out_srs} '
|
'-t_srs {out_srs} '
|
||||||
'{input} '
|
'{input} '
|
||||||
'{output} '.format(**kwargs))
|
'{output} '
|
||||||
|
'--config GDAL_CACHEMAX {max_memory}% '.format(**kwargs))
|
||||||
return out_file
|
return out_file
|
||||||
|
|
||||||
def compute_alignment_matrix(input_laz, align_file, stats_dir):
|
def compute_alignment_matrix(input_laz, align_file, stats_dir):
|
||||||
|
@ -69,52 +72,53 @@ def compute_alignment_matrix(input_laz, align_file, stats_dir):
|
||||||
return
|
return
|
||||||
|
|
||||||
to_delete = []
|
to_delete = []
|
||||||
log.ODM_INFO("Align CRS: %s" % align_crs)
|
|
||||||
if input_crs != align_crs:
|
|
||||||
# Reprojection needed
|
|
||||||
log.ODM_INFO("Reprojecting %s to %s" % (align_file, input_crs))
|
|
||||||
align_file = repr_func(align_file, input_crs)
|
|
||||||
to_delete.append(align_file)
|
|
||||||
|
|
||||||
conf = dataclasses.asdict(codem.CodemRunConfig(align_file, input_laz, OUTPUT_DIR=stats_dir))
|
try:
|
||||||
fnd_obj, aoi_obj = codem.preprocess(conf)
|
log.ODM_INFO("Align CRS: %s" % align_crs)
|
||||||
fnd_obj.prep()
|
if input_crs != align_crs:
|
||||||
aoi_obj.prep()
|
# Reprojection needed
|
||||||
log.ODM_INFO("Aligning reconstruction to %s" % align_file)
|
log.ODM_INFO("Reprojecting %s to %s" % (align_file, input_crs))
|
||||||
log.ODM_INFO("Coarse registration...")
|
align_file = repr_func(align_file, input_crs)
|
||||||
dsm_reg = codem.coarse_registration(fnd_obj, aoi_obj, conf)
|
to_delete.append(align_file)
|
||||||
log.ODM_INFO("Fine registration...")
|
|
||||||
icp_reg = codem.fine_registration(fnd_obj, aoi_obj, dsm_reg, conf)
|
|
||||||
|
|
||||||
app_reg = codem.registration.ApplyRegistration(
|
conf = dataclasses.asdict(codem.CodemRunConfig(align_file, input_laz, OUTPUT_DIR=stats_dir))
|
||||||
fnd_obj,
|
fnd_obj, aoi_obj = codem.preprocess(conf)
|
||||||
aoi_obj,
|
fnd_obj.prep()
|
||||||
icp_reg.registration_parameters,
|
aoi_obj.prep()
|
||||||
icp_reg.residual_vectors,
|
log.ODM_INFO("Aligning reconstruction to %s" % align_file)
|
||||||
icp_reg.residual_origins,
|
log.ODM_INFO("Coarse registration...")
|
||||||
conf,
|
dsm_reg = codem.coarse_registration(fnd_obj, aoi_obj, conf)
|
||||||
None,
|
log.ODM_INFO("Fine registration...")
|
||||||
)
|
icp_reg = codem.fine_registration(fnd_obj, aoi_obj, dsm_reg, conf)
|
||||||
|
|
||||||
reg = app_reg.get_registration_transformation()
|
app_reg = codem.registration.ApplyRegistration(
|
||||||
|
fnd_obj,
|
||||||
# Write JSON to stats folder
|
aoi_obj,
|
||||||
with open(os.path.join(stats_dir, "registration.json"), 'w') as f:
|
icp_reg.registration_parameters,
|
||||||
del dsm_reg.registration_parameters['matrix']
|
icp_reg.residual_vectors,
|
||||||
del icp_reg.registration_parameters['matrix']
|
icp_reg.residual_origins,
|
||||||
|
conf,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
|
||||||
f.write(json.dumps({
|
reg = app_reg.get_registration_transformation()
|
||||||
'coarse': dsm_reg.registration_parameters,
|
|
||||||
'fine': icp_reg.registration_parameters,
|
# Write JSON to stats folder
|
||||||
}, indent=4))
|
with open(os.path.join(stats_dir, "registration.json"), 'w') as f:
|
||||||
|
del dsm_reg.registration_parameters['matrix']
|
||||||
|
del icp_reg.registration_parameters['matrix']
|
||||||
|
|
||||||
matrix = np.fromstring(reg['matrix'], dtype=float, sep=' ').reshape((4, 4))
|
f.write(json.dumps({
|
||||||
|
'coarse': dsm_reg.registration_parameters,
|
||||||
|
'fine': icp_reg.registration_parameters,
|
||||||
|
}, indent=4))
|
||||||
|
|
||||||
for f in to_delete:
|
matrix = np.fromstring(reg['matrix'], dtype=float, sep=' ').reshape((4, 4))
|
||||||
if os.path.isfile(f):
|
return matrix
|
||||||
os.unlink(f)
|
finally:
|
||||||
|
for f in to_delete:
|
||||||
return matrix
|
if os.path.isfile(f):
|
||||||
|
os.unlink(f)
|
||||||
|
|
||||||
def transform_point_cloud(input_laz, a_matrix, output_laz):
|
def transform_point_cloud(input_laz, a_matrix, output_laz):
|
||||||
pipe = [
|
pipe = [
|
||||||
|
|
|
@ -185,7 +185,12 @@ class ODMGeoreferencingStage(types.ODM_Stage):
|
||||||
if alignment_file_exists:
|
if alignment_file_exists:
|
||||||
os.unlink(tree.odm_georeferencing_alignment_matrix)
|
os.unlink(tree.odm_georeferencing_alignment_matrix)
|
||||||
|
|
||||||
a_matrix = compute_alignment_matrix(tree.odm_georeferencing_model_laz, tree.odm_align_file, stats_dir)
|
a_matrix = None
|
||||||
|
try:
|
||||||
|
a_matrix = compute_alignment_matrix(tree.odm_georeferencing_model_laz, tree.odm_align_file, stats_dir)
|
||||||
|
except Exception as e:
|
||||||
|
log.ODM_WARNING("Cannot compute alignment matrix: %s" % str(e))
|
||||||
|
|
||||||
if a_matrix is not None:
|
if a_matrix is not None:
|
||||||
log.ODM_INFO("Alignment matrix: %s" % a_matrix)
|
log.ODM_INFO("Alignment matrix: %s" % a_matrix)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue