Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: LFSantosgeo on February 14, 2019, 06:08:40 AM
-
Hello!
Is there any script to export MetaShape XML markers into text file with marker labels, photo labels and 2D coordinates from markers projections in the photos? Output something like:
#marker_label #photo_label #img_x # img_y
I've run into lots of exemples of the opposite procedure...
Thanks in advance!
-
Hello Luiz,
You can try to use this script sample:
file = open(path, "wt")
chunk = Metashape.app.document.chunk
photos_total = len(chunk.cameras) #number of photos in chunk
markers_total = len(chunk.markers) #number of markers in chunk
if (markers_total):
file.write(chunk.label + "\n")
for i in range (0, markers_total): #processing every marker in chunk
cur_marker = chunk.markers[i]
cur_projections = cur_marker.projections #list of marker projections
marker_name = cur_marker.label
for camera in cur_marker.projections.keys(): #
#for j in range (0, len(photos_list)): #processing every projection of the current marker
x, y = cur_projections[camera].coord #x and y coordinates of the current projection in pixels
label = camera.label
file.write(marker_name + "," + label + "," + "{:.4f}".format(x) + "," + "{:.4f}".format(y) + "\n") #writing output
file.write("#\n")
file.close()
-
Hello Alexey,
It works! Thank you very much!
Hello Luiz,
You can try to use this script sample:
file = open(path, "wt")
chunk = Metashape.app.document.chunk
photos_total = len(chunk.cameras) #number of photos in chunk
markers_total = len(chunk.markers) #number of markers in chunk
if (markers_total):
file.write(chunk.label + "\n")
for i in range (0, markers_total): #processing every marker in chunk
cur_marker = chunk.markers[i]
cur_projections = cur_marker.projections #list of marker projections
marker_name = cur_marker.label
for camera in cur_marker.projections.keys(): #
#for j in range (0, len(photos_list)): #processing every projection of the current marker
x, y = cur_projections[camera].coord #x and y coordinates of the current projection in pixels
label = camera.label
file.write(marker_name + "," + label + "," + "{:.4f}".format(x) + "," + "{:.4f}".format(y) + "\n") #writing output
file.write("#\n")
file.close()