Forum

Author Topic: Marker pixel error in Python  (Read 2564 times)

Hugh

  • Newbie
  • *
  • Posts: 19
    • View Profile
Marker pixel error in Python
« on: June 22, 2022, 11:57:19 AM »
Hi,

In the Metashape UI, when I create markers, one of the columns is "Error (pix)". I can see this value in the UI, but I can't figure out how to get it in Python.

For reference, I'm creating the markers using Python:

Code: [Select]
marker = chunk.addMarker()
for projection in projection_cameras:
    marker.projections[projection['camera']] = Metashape.Marker.Projection(Metashape.Marker(projection['position']))

Thanks

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Marker pixel error in Python
« Reply #1 on: June 22, 2022, 02:20:28 PM »
Hello Hugh,

Please try this code to print out to the Console the projection error in pix for the markers:
Code: [Select]
import Metashape, math
chunk = Metashape.app.document.chunk
print("Script started...")
for marker in chunk.markers:
if not marker.position:
print(marker.label + " is not defined in 3D, skipping...")
continue
position = marker.position
proj_error = list()
proj_sqsum = 0
for camera in marker.projections.keys():
if not camera.transform:
continue #skipping not aligned cameras
image_name = camera.label
proj = marker.projections[camera].coord
reproj = camera.project(marker.position)
error = reproj - proj
proj_error.append(error.norm())
proj_sqsum += error.norm()**2
if len(proj_error):
error = math.sqrt(proj_sqsum / len(proj_error))
print(marker.label + " projection error: " + error)
print("Script finished.")
Best regards,
Alexey Pasumansky,
Agisoft LLC