kopia lustrzana https://github.com/OpenDroneMap/WebODM
Remove align
rodzic
b32b617297
commit
28b512dfdd
|
@ -1,8 +0,0 @@
|
|||
from .rasterize import rasterize_cloud
|
||||
from .cloud_compare import run_icp
|
||||
|
||||
def rasterize(point_cloud_path, dem_type, raster_path):
|
||||
rasterize_cloud(point_cloud_path, dem_type, raster_path)
|
||||
|
||||
def align(reference_pcl_path, pcl_to_modify_path, output_path):
|
||||
run_icp(reference_pcl_path, pcl_to_modify_path, output_path)
|
|
@ -1,24 +0,0 @@
|
|||
import subprocess, shlex, os, glob
|
||||
|
||||
def run_icp(reference_pcl_path, pcl_to_modify_path, output_path):
|
||||
command = __icp_command(reference_pcl_path, pcl_to_modify_path, output_path)
|
||||
__execute(command)
|
||||
for txt in glob.glob(os.path.dirname(pcl_to_modify_path) + '/*.txt'):
|
||||
os.remove(txt)
|
||||
|
||||
def __execute(command):
|
||||
# subprocess.call(shlex.split(command), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
subprocess.call(shlex.split(command))
|
||||
|
||||
def __icp_command(reference_pcl_path, pcl_to_modify_path, output_path):
|
||||
return """CloudCompare \
|
||||
-SILENT \
|
||||
-AUTO_SAVE OFF \
|
||||
-C_EXPORT_FMT LAS \
|
||||
-O {moving} \
|
||||
-O {reference} \
|
||||
-ICP \
|
||||
-SAVE_CLOUDS FILE '{output_path}'""".format(
|
||||
reference=reference_pcl_path,
|
||||
moving=pcl_to_modify_path,
|
||||
output_path=output_path)
|
|
@ -1,29 +0,0 @@
|
|||
import os, tempfile
|
||||
from string import Template
|
||||
import subprocess
|
||||
|
||||
def rasterize_dtm(input_pcl, output_tif, resolution = 0.1):
|
||||
__run('dtm_rasterize', fin=input_pcl, output_tif=output_tif, resolution=resolution)
|
||||
|
||||
def rasterize_dsm(input_pcl, output_tif, resolution = 0.1):
|
||||
__run('dsm_rasterize', fin=input_pcl, output_tif=output_tif, resolution=resolution)
|
||||
|
||||
def info(input_pcl):
|
||||
command = 'pdal info -i \'{}\' --enumerate Classification'.format(input_pcl)
|
||||
output = subprocess.check_output(command, shell=True)
|
||||
return output
|
||||
|
||||
def __run(template_name, **kwparams):
|
||||
template = __get_template(template_name)
|
||||
pipeline_definition = template.substitute(kwparams)
|
||||
with tempfile.NamedTemporaryFile(suffix='.json', mode='w') as pipeline:
|
||||
pipeline.write(pipeline_definition)
|
||||
pipeline.flush()
|
||||
command = 'pdal pipeline \'{}\''.format(pipeline.name)
|
||||
output = subprocess.check_output(command, shell=True)
|
||||
|
||||
|
||||
def __get_template(template_name):
|
||||
dir = os.path.dirname(os.path.realpath(__file__))
|
||||
with open(os.path.join(dir, 'pipelines', template_name + '.json')) as pipeline_template:
|
||||
return Template(pipeline_template.read())
|
|
@ -1,14 +0,0 @@
|
|||
[
|
||||
"${fin}",
|
||||
{
|
||||
"type": "filters.range",
|
||||
"limits": "Classification![2:2]"
|
||||
},
|
||||
{
|
||||
"type": "writers.gdal",
|
||||
"resolution": ${resolution},
|
||||
"filename": "${output_tif}",
|
||||
"output_type": "max",
|
||||
"data_type": "float"
|
||||
}
|
||||
]
|
|
@ -1,14 +0,0 @@
|
|||
[
|
||||
"${fin}",
|
||||
{
|
||||
"type": "filters.range",
|
||||
"limits": "Classification[2:2]"
|
||||
},
|
||||
{
|
||||
"type": "writers.gdal",
|
||||
"resolution": ${resolution},
|
||||
"filename": "${output_tif}",
|
||||
"output_type": "idw",
|
||||
"data_type": "float"
|
||||
}
|
||||
]
|
|
@ -1,52 +0,0 @@
|
|||
import rasterio as rio
|
||||
from scipy import ndimage
|
||||
import tempfile, subprocess, os
|
||||
import json
|
||||
from .pdal import pdal
|
||||
|
||||
def rasterize_cloud(point_cloud_path, dem_type, raster_path):
|
||||
__verify_point_cloud_was_classified(point_cloud_path)
|
||||
with tempfile.NamedTemporaryFile(suffix='.tif') as temp_tif:
|
||||
if dem_type == 'dtm':
|
||||
pdal.rasterize_dtm(point_cloud_path, temp_tif.name)
|
||||
else:
|
||||
pdal.rasterize_dsm(point_cloud_path, temp_tif.name)
|
||||
__fill(temp_tif.name, raster_path)
|
||||
|
||||
def __verify_point_cloud_was_classified(point_cloud_path):
|
||||
info = pdal.info(point_cloud_path)
|
||||
info = json.loads(info)
|
||||
dimensions = info['stats']['statistic']
|
||||
classification = [ dimension for dimension in dimensions if dimension['name'] == 'Classification'][0]
|
||||
if 2 not in classification['values']:
|
||||
raise Exception("One of the tasks' point cloud wasn't classified. Please run again with 'pc-classify'.")
|
||||
|
||||
def __fill(fin, fout):
|
||||
subprocess.run(['gdal_fillnodata.py', '-q', '-b', '1', '-of', 'GTiff', fin, fin])
|
||||
__median_smoothing(fin, fout)
|
||||
|
||||
def __median_smoothing(input_path, output_path, smoothing_iterations = 1):
|
||||
with rio.open(input_path) as input_raster:
|
||||
dtype = input_raster.dtypes[0]
|
||||
arr = input_raster.read(1)
|
||||
mask = arr == input_raster.nodata
|
||||
|
||||
# Median filter (careful, changing the value 5 might require tweaking)
|
||||
# the lines below. There's another numpy function that takes care of
|
||||
# these edge cases, but it's slower.
|
||||
for i in range(smoothing_iterations):
|
||||
arr = ndimage.median_filter(arr, size = 5, output = dtype)
|
||||
|
||||
# Fill corner points with nearest value
|
||||
if arr.shape >= (4, 4):
|
||||
arr[0][:2] = arr[1][0] = arr[1][1]
|
||||
arr[0][-2:] = arr[1][-1] = arr[2][-1]
|
||||
arr[-1][:2] = arr[-2][0] = arr[-2][1]
|
||||
arr[-1][-2:] = arr[-2][-1] = arr[-2][-2]
|
||||
|
||||
# Median filter leaves a bunch of zeros in nodata areas
|
||||
arr[mask == True] = input_raster.nodata
|
||||
|
||||
# write output
|
||||
with rio.open(output_path, 'w', **input_raster.profile) as output_raster:
|
||||
output_raster.write(arr, 1)
|
Ładowanie…
Reference in New Issue