kopia lustrzana https://github.com/OpenDroneMap/ODM
working on point cloud io
rodzic
7c855688a1
commit
34311a2380
|
@ -12,72 +12,40 @@ def read_cloud(point_cloud_path):
|
||||||
|
|
||||||
# Open point cloud and read its properties using pdal
|
# Open point cloud and read its properties using pdal
|
||||||
pipeline = pdal.Pipeline('[{"type":"readers.las","filename":"%s"}]' % point_cloud_path)
|
pipeline = pdal.Pipeline('[{"type":"readers.las","filename":"%s"}]' % point_cloud_path)
|
||||||
cnt = pipeline.execute()
|
pipeline.execute()
|
||||||
|
|
||||||
log.ODM_INFO("pdal arrays: %s" % pipeline.arrays)
|
metadata = pipeline.metadata
|
||||||
|
arrays = pipeline.arrays
|
||||||
|
|
||||||
dimensions = pipeline.schema['schema']['dimensions']
|
# Extract point coordinates, classification, and RGB values
|
||||||
#log.ODM_INFO("Type: %s" % type(pipeline.schema))
|
x = arrays[0]["X"]
|
||||||
log.ODM_INFO("Dimensions: %s" % dimensions)
|
y = arrays[0]["Y"]
|
||||||
|
z = arrays[0]["Z"]
|
||||||
# The x column index is the index of the object with the name 'X'
|
classification = arrays[0]["Classification"].astype(np.uint8)
|
||||||
x_index = next((index for (index, d) in enumerate(dimensions) if d['name'] == 'X'), None)
|
red = arrays[0]["Red"]
|
||||||
y_index = next((index for (index, d) in enumerate(dimensions) if d['name'] == 'Y'), None)
|
green = arrays[0]["Green"]
|
||||||
z_index = next((index for (index, d) in enumerate(dimensions) if d['name'] == 'Z'), None)
|
blue = arrays[0]["Blue"]
|
||||||
classification_index = next((index for (index, d) in enumerate(dimensions) if d['name'] == 'Classification'), None)
|
|
||||||
red_index = next((index for (index, d) in enumerate(dimensions) if d['name'] == 'Red'), None)
|
|
||||||
green_index = next((index for (index, d) in enumerate(dimensions) if d['name'] == 'Green'), None)
|
|
||||||
blue_index = next((index for (index, d) in enumerate(dimensions) if d['name'] == 'Blue'), None)
|
|
||||||
|
|
||||||
# Log indices
|
|
||||||
log.ODM_INFO("x_index: %s" % x_index)
|
|
||||||
log.ODM_INFO("y_index: %s" % y_index)
|
|
||||||
log.ODM_INFO("z_index: %s" % z_index)
|
|
||||||
log.ODM_INFO("classification_index: %s" % classification_index)
|
|
||||||
log.ODM_INFO("red_index: %s" % red_index)
|
|
||||||
log.ODM_INFO("green_index: %s" % green_index)
|
|
||||||
log.ODM_INFO("blue_index: %s" % blue_index)
|
|
||||||
|
|
||||||
pts = pipeline.arrays[0]
|
|
||||||
log.ODM_INFO("pts: %s" % pts)
|
|
||||||
|
|
||||||
x = (pt[x_index] for pt in pts)
|
|
||||||
y = (pt[y_index] for pt in pts)
|
|
||||||
z = (pt[z_index] for pt in pts)
|
|
||||||
classification = (pt[classification_index] for pt in pts)
|
|
||||||
red = (pt[red_index] for pt in pts)
|
|
||||||
green = (pt[green_index] for pt in pts)
|
|
||||||
blue = (pt[blue_index] for pt in pts)
|
|
||||||
|
|
||||||
|
# Create PointCloud object
|
||||||
cloud = PointCloud.with_dimensions(x, y, z, classification, red, green, blue)
|
cloud = PointCloud.with_dimensions(x, y, z, classification, red, green, blue)
|
||||||
|
|
||||||
# Return the result
|
# Return the result
|
||||||
return pipeline.metadata, cloud
|
return metadata, cloud
|
||||||
|
|
||||||
def write_cloud(header, point_cloud, output_point_cloud_path, write_extra_dimensions=False):
|
def write_cloud(metadata, point_cloud, output_point_cloud_path, write_extra_dimensions=False):
|
||||||
# Open output file
|
|
||||||
output_las_file = laspy.LasData(header)
|
|
||||||
|
|
||||||
if write_extra_dimensions:
|
# Create PDAL pipeline to write point cloud
|
||||||
extra_dims = [laspy.ExtraBytesParams(name=name, type=dimension.get_las_type(), description="Dimension added by Ground Extend") for name, dimension in point_cloud.extra_dimensions_metadata.items()]
|
pipeline = pdal.Pipeline('[{"type": "writers.las","filename": "%s","compression": "laszip","extra_dims": %s}]' %
|
||||||
output_las_file.add_extra_dims(extra_dims)
|
(output_point_cloud_path, str(write_extra_dimensions).lower()))
|
||||||
# Assign dimension values
|
|
||||||
for dimension_name, values in point_cloud.extra_dimensions.items():
|
|
||||||
setattr(output_las_file, dimension_name, values)
|
|
||||||
|
|
||||||
# Adapt points to scale and offset
|
# Adapt points to scale and offset
|
||||||
[x, y] = np.hsplit(point_cloud.xy, 2)
|
[x, y] = np.hsplit(point_cloud.xy, 2)
|
||||||
output_las_file.x = x.ravel()
|
z = point_cloud.z
|
||||||
output_las_file.y = y.ravel()
|
|
||||||
output_las_file.z = point_cloud.z
|
|
||||||
|
|
||||||
# Set color
|
# Set color
|
||||||
[red, green, blue] = np.hsplit(point_cloud.rgb, 3)
|
[red, green, blue] = np.hsplit(point_cloud.rgb, 3)
|
||||||
output_las_file.red = red.ravel()
|
|
||||||
output_las_file.green = green.ravel()
|
|
||||||
output_las_file.blue = blue.ravel()
|
|
||||||
|
|
||||||
# Set classification
|
# Set classification
|
||||||
output_las_file.classification = point_cloud.classification.astype(np.uint8)
|
classification = point_cloud.classification.astype(np.uint8)
|
||||||
|
|
||||||
output_las_file.write(output_point_cloud_path)
|
# Write point cloud with PDAL
|
||||||
|
pipeline.execute(np.column_stack((x, y, z, red, green, blue, classification)))
|
||||||
|
|
Ładowanie…
Reference in New Issue