Forum

Author Topic: Markers XML to Text File  (Read 2637 times)

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Markers XML to Text File
« 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!
Luiz Fernando

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14843
    • View Profile
Re: Markers XML to Text File
« Reply #1 on: February 14, 2019, 12:05:28 PM »
Hello Luiz,

You can try to use this script sample:

Code: [Select]
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()
Best regards,
Alexey Pasumansky,
Agisoft LLC

LFSantosgeo

  • Jr. Member
  • **
  • Posts: 70
    • View Profile
Re: Markers XML to Text File
« Reply #2 on: February 14, 2019, 06:26:41 PM »
Hello Alexey,

It works! Thank you very much!


Hello Luiz,

You can try to use this script sample:

Code: [Select]
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()
Luiz Fernando