Closed SamueleBumbaca closed 2 months ago
Hi,
Metashape_2.1.3 Metashape Python Reference (agisoft.com) module manual describes class Metashape.PointCloud.Points (pag 121) as a list, instead I found it to be 'type'. This means that is not iterable and the points are not written in. Where can I access individual point of the point cloud?
You mean that you find unexpected that type(Metashape.PointCloud.Points)
prints type
instead of list
? This is because this is a name of a class, so Points
is a type
just like any other class (including list). For example, if you execute type(list)
- you will also get type
as a result:
About your use-case (as my colleague replied):
Currently there is no direct way to interact with the dense point cloud points, so please check, how it could be done by exporting the point and then treating it as o3d/np arrays: https://github.com/agisoft-llc/metashape-scripts/blob/master/src/align_model_to_model.py
Alternatively, you can use PointCloud.Reader()
class:
reader = Metashape.PointCloud.Reader()
reader.open(chunk.point_cloud)
points = reader.read(10000)
In such manner you can access the points of the dense point cloud by blocks (like 10000 in the given example), as the complete point cloud could be too large to be loaded to the variable at once. And here you will have points of Metashape.PointCloud.Points class and each element of this array would be of Metashape.PointCloud.Point class.
Also keep in mind that processing large numbers (>million) of elements (points) on per-element-basis is very slow in Python.
I really appreciate your and your colleague's help and I apologise for the misleading.
For the use case I found ColorizePointCloud or ColorizeModel as solution. For example, on mesh, you can colour the model with the segmentation binary mask. This will result in a mesh with vertices and faces colours somehow equal to the probability of being of the segmentation class.
import Metashape
def export_class_color_mesh(label):
doc = Metashape.Document()
doc.open('')
mask_path_list = ''
chunk = doc.chunk
# Get the cameras
cameras = chunk.cameras
for camera, mask_path in zip(cameras, mask_path_list):
camera.photo.path = mask_path
colorizeModel = Metashape.Tasks.ColorizeModel()
colorizeModel.source_data = Metashape.DataSource.ImagesData
colorizeModel.apply(chunk)
chunk.exportModel('')
Main problem
Metashape_2.1.3 Metashape Python Reference (agisoft.com) module manual describes class Metashape.PointCloud.Points (pag 121) as a list, instead I found it to be 'type'. This means that is not iterable and the points are not written in. Where can I access individual point of the point cloud?
in context I want to segment the point cloud (and mesh vertices) by aligned and semantically segmented photos. As shown in https://github.com/JordanMakesMaps/3D-Model-Classification/tree/main, one can colorize the point cloud (or the model) by colorize dense points in GUI, but how to do that in Python?
I tryied in this way: assign the classes to the points of the point cloud as the final step of semantically segmenting the pictures of the alignment and mapping the segmentation on the point cloud by projecting the image coordinates in the point cloud coordinates.
but I cannot iterate on pc.Points (TypeError: 'type' object is not iterable) as pc.Points.class == <class 'type'>