Forum

Author Topic: How to export Markers location and errors pix in a txt file  (Read 5066 times)

SixenseLamier

  • Newbie
  • *
  • Posts: 7
    • View Profile
Hello,
I would like export just some markers and the errors pix of them in a txt file.
I've found this code to export all markers location.

Code: [Select]
# exports all markers in activeChunk to csv.

import Metashape, math
FILEPATH = 'C:/Alexandre/PFE/Python/Resultat_export/marker_export.txt'



doc = Metashape.app.document
chunk = doc.chunk
T = chunk.transform.matrix
f = open(FILEPATH, 'w')
for item in chunk.markers:
   if item.position == None:
      continue
   v = item.position
   v.size = 4
   v.w = 1
   if not chunk.transform:
      chunk.transform.matrix = Metashape.Matrix.Diag( (1,1,1,1) )
   T = chunk.transform.matrix
   v_t = T * v
   v_t.size = 3
   proj = chunk.crs
   v_out = proj.project(v_t)
   f.write(item.label + ',' + str(v_out[0]) + ',' + str(v_out[1]) + ',' + str(v_out[2]) +  '\n')
f.close()

But how to make if I just want the markers
  • ,[1],[2], [3], [4],[5]


In addition, I would like export the error pix of each marker. Is it possible ?

Regards,
Alex

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15168
    • View Profile
Re: How to export Markers location and errors pix in a txt file
« Reply #1 on: July 04, 2019, 09:58:37 PM »
Hello Alex,

Is that correct that you need only projection error values in pixels for selected markers (or a list of markers defined by their labels)?
Best regards,
Alexey Pasumansky,
Agisoft LLC

SixenseLamier

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How to export Markers location and errors pix in a txt file
« Reply #2 on: July 08, 2019, 03:51:37 PM »
Hello,

I just need a list of the error proj of markers defined by their labels.


Alex
Regards

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15168
    • View Profile
Re: How to export Markers location and errors pix in a txt file
« Reply #3 on: July 08, 2019, 08:34:25 PM »
Hello Alex,

Please check if the following script gives you the desired result, it outputs the marker labels and corresponding error to the Console pane (but you can easily redirect it to the external file):
Code: [Select]
import Metashape, math

def find_marker(label, chunk):
for marker in chunk.markers:
if label == marker.label:
return marker
return None

MARKERS = ["point 1", "point 2"]
chunk = Metashape.app.document.chunk
print("Script started...")

for name in MARKERS:

marker = find_marker(name, chunk)
if not marker:
print(name + " not found, skipping...")
continue

if not marker.position:
print(name + " is not defined in 3D, skipping...")
continue
position = marker.position

total = (0, 0)
for camera in marker.projections.keys():
if not camera.transform:
continue
proj = marker.projections[camera].coord
reproj = camera.project(marker.position)
error = (proj - reproj).norm()
total = (total[0] + error**2, total[1] + 1)

print(marker.label, math.sqrt(total[0] / total [1]))
print("Script finished")

The list of marker labels to be processed is defined in the script body as a MARKERS list.
Best regards,
Alexey Pasumansky,
Agisoft LLC

SixenseLamier

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: How to export Markers location and errors pix in a txt file
« Reply #4 on: July 09, 2019, 09:37:26 AM »
Hello !

It works very good, I replaced "point 1, ... " by my labels !
I will write the end, to export it in txt file

Thanks a lot.

Regards !
Alex :D :D :D