agisoft-llc / metashape-scripts

Python scripts for Metashape (former PhotoScan)
MIT License
355 stars 199 forks source link

ExportPoints in Metashape #25

Closed kaichand9 closed 3 years ago

kaichand9 commented 3 years ago

Can someone help me in exporting clipped point cloud using python code in Metashape. I am using 1.6.4 version of Agisoft

PolarNick239 commented 3 years ago

Hi,

Please refer to Python API - there are exportPoints(...) function, so:

If you need to export Dense Cloud points clipped to bounding box (region):

Metashape.app.document.chunk.exportPoints(path="...dense_cloud_clipped.ply", source_data=Metashape.DenseCloudData, clip_to_boundary=True)

If you need to export Tie Points (sparse cloud) clipped to bounding box (region):

Metashape.app.document.chunk.exportPoints(path="...tie_points_clipped.ply", source_data=Metashape.PointCloudData, clip_to_boundary=True)
kaichand9 commented 3 years ago

Thanks for suggestions I wanted to export in .las file

I am using metashape 1.6.4 version.

Giving error in export format. I tried following - las, asprs las, pointformatlas. But not taking giving some error. Script below

import Metashape import os

doc = Metashape.app.document chunk = doc.chunk

path = Metashape.app.getSaveFileName("Export Points")

export_point_config = { 'binary': True, 'normals': True, 'colors': True, 'confidence':True 'format': 'LAS', }

chunk.exportPoints(path, **export_point_config)

Script running but no data/ files coming

PolarNick239 commented 3 years ago

Can you please provide error message from console?

kaichand9 commented 3 years ago

Ok image

PolarNick239 commented 3 years ago

It is due to a missing comma in the previous line: confidence:True.

After other fixes w.r.t. exportPoints signature in Python API:

import Metashape
import os

doc = Metashape.app.document
chunk = doc.chunk

path = Metashape.app.getSaveFileName("Export Points")

export_point_config = {
'binary': True,
'save_normals': True, # changed
'save_colors': True, # changed
'save_confidence':True, # changed
'format': Metashape.PointsFormatLAS, # changed
}

chunk.exportPoints(path, **export_point_config)
kaichand9 commented 3 years ago

Highly appreciate your help. Script is working fine now. Exporting but only issue left is projection get changed to Geographic projection. Projection getting changed to Geographic, Not taking in which data processed in Metashape.

PolarNick239 commented 3 years ago

Do you want to export in Local Coordinates like via GUI dialog? If so:

import Metashape
import os

doc = Metashape.app.document
chunk = doc.chunk

path = Metashape.app.getSaveFileName("Export Points")

export_point_config = {
'binary': True,
'save_normals': True,
'save_colors': True,
'save_confidence':True,
'format': Metashape.PointsFormatLAS,
'crs': Metashape.CoordinateSystem('LOCAL_CS["Local Coordinates(m)",LOCAL_DATUM["Local Datum",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]'), # changed
}

chunk.exportPoints(path, **export_point_config)
kaichand9 commented 3 years ago

Thanks for help. Yes I want to export like GUI. But when export using GUI it take default projection in which I have done processing in metashape Just after adding photos and processing I have defined projection system (WGS to EPSG -20355), then why it is asking to re-define projection again while exporting Point cloud using python. I just want projection to be exported in which I have done all the processing., Appreciate your help

PolarNick239 commented 3 years ago

Then you can use chunk.crs:

import Metashape
import os

doc = Metashape.app.document
chunk = doc.chunk

path = Metashape.app.getSaveFileName("Export Points")

export_point_config = {
'binary': True,
'save_normals': True,
'save_colors': True,
'save_confidence':True,
'format': Metashape.PointsFormatLAS,
'crs': chunk.crs, # changed
}

chunk.exportPoints(path, **export_point_config)
kaichand9 commented 3 years ago

Thanks mate. Script is working fine. Appreciate your support