Forum

Author Topic: How can I extract the point cloud in ply file from the python Script?  (Read 2351 times)

lyhour

  • Newbie
  • *
  • Posts: 41
    • View Profile
I am new to python Agisoft. I try to export the point similar process to the GUI. However, it raised the error : Value Error: Invalid argument value: format. The code is shown in the below. Also, How can I choose between the dense point cloud and spare point cloud in the coding ? Moreover, I notice that the computation time is very different. When I use the GUI the processing time is very fast. But when I use the python API, it takes longer time. Do anyone know how to fix it. Thank you very much.
Code: [Select]
import Metashape
import textwrap
import glob
import os
global doc
doc = Metashape.app.document
print("Script started")

#creating new chunk
doc.addChunk()
chunk = doc.chunk
chunk.label = "New Chunk"

photo_list = list()
image_dir='Picture'
path_img = os.path.join(os.getcwd(),image_dir)
for j,img_file in enumerate(glob.glob(path_img+'/*.jpg')):
img_name = os.path.splitext(os.path.basename(img_file))[0]
photo_list.append(img_file)


keypoints = 40000 #align photos key point limit
tiepoints = 10000 #align photos tie point limit
chunk.addPhotos(photo_list)
#align photos
chunk.matchPhotos(downscale=1, generic_preselection=True, filter_mask = False, keypoint_limit = keypoints, tiepoint_limit = tiepoints)
chunk.alignCameras()

chunk.optimizeCameras()

chunk.buildDepthMaps(downscale=4, filter_mode=Metashape.AggressiveFiltering)
chunk.buildDenseCloud()
#building mesh
chunk.buildModel(surface_type=Metashape.Arbitrary, interpolation=Metashape.EnabledInterpolation)

#build texture

chunk.buildUV(mapping_mode=Metashape.GenericMapping)

chunk.buildTexture(blending_mode=Metashape.MosaicBlending, texture_size=4096)
Metashape.app.update()

#export
output_dir='Picture'
path_out = os.path.join(os.getcwd(),output_dir)

chunk.exportPoints(path = path_out + "/model.ply", format = "ply", colors = True)

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: How can I extract the point cloud in ply file from the python Script?
« Reply #1 on: October 14, 2021, 05:44:59 PM »
Hi lyhour,

please look at p. 34 of Metashape  API reference guide https://www.agisoft.com/pdf/metashape_python_api_1_7_5.pdf:
Code: [Select]
exportPoints(path='', source_data=Metashape.DenseCloudData, binary=True, save_normals=True,
save_colors=True, save_classes=True, save_confidence=True,
raster_transform=RasterTransformNone, colors_rgb_8bit=True, comment='',
save_comment=True, format=Metashape.PointsFormatPLY, image_format=ImageFormatJPEG[, crs
][, shift ][, region ], clip_to_boundary=True, block_width=1000, block_height=1000,
split_in_blocks=False[, classes ], save_images=False, compression=True[, viewpoint ],
subdivide_task=True[, progress ])
where source_data = Metashape.DenseCloudData specifies dense cloud as source and
format = Metashape.PointsFormatPLY specifies PLY export format...

Hope this helps,
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How can I extract the point cloud in ply file from the python Script?
« Reply #2 on: October 14, 2021, 06:09:53 PM »
Hello lyhour,

As for the computation time, do you use GPU for processing via GUI? If so, then you should probably enable it in the Python code to benefit from GPU acceleration.

The following lines should be added to the script before any GPU-supported processing operation is started, if you would like to enable all the available GPU devices for the processing:
Code: [Select]
Metashape.app.gpu_mask = 2 ** len(Metashape.app.enumGPUDevices()) - 1
if Metashape.app.gpu_mask:
    Metashape.app.cpu_enable = False
Best regards,
Alexey Pasumansky,
Agisoft LLC

lyhour

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: How can I extract the point cloud in ply file from the python Script?
« Reply #3 on: October 14, 2021, 06:41:11 PM »
Dear Paul Pelletier,
I really appreciate your reply. Thank you very much for you information. It would be better if you could help me one more question. I want to define my coordinate system as local coordinate. How can I set it ? I saw some documentation but I don't know how to use it. Again, thank you very much

Best Regards,
CHHAY LYHOUR

lyhour

  • Newbie
  • *
  • Posts: 41
    • View Profile
Re: How can I extract the point cloud in ply file from the python Script?
« Reply #4 on: October 14, 2021, 06:45:49 PM »
Dear Alexey Pasumansky,
Thank you very much for your reply. I really appreciate your respond. In the GUI, I use the GPU to run it. However, in the python API I am not sure as well. But, when I see the status in the command, it showed about the information of GPU memory usage. I will input your suggestion coding and see the result. Again, thank you very much.

Best Regards,
CHHAY LYHOUR