Forum

Author Topic: Access estimated location of markers through Python  (Read 3461 times)

Access estimated location of markers through Python
« on: April 10, 2019, 12:17:47 PM »
I am working with a test project containing two images. Both shot from approximately 3 m towards the floor. The photos have been taken handheld with a DSLR.

Summary of the project:
  • Seven markers (coded targets)
  • Four markers are reference markers with a known location, all of them in a plain (floor)
  • The reference markers define the coordinate system. I enter their known location into the reference pane
  • Three markers, that I want to get their location. The location should be in respect to the coordinate system defined by the reference markers

If I switch to "View Estimated" in the reference pane, Metashape shows me the location of the unknown markers in meters. However, if I try to access the values through Python, it returns None, see code below.

I can access the positions of the markers and could transform them into meters myself and align them with my coordinate system in python (see code bellow). However, it would be nice to get the location of the markers from Metashape since they are known to Metashape.


My Question:
How can I access the locations of the markers through the Python API?

Printing the location of the markers:
Code: [Select]
>>> chunk = Metashape.app.document.chunks[0]
>>> for marker in chunk.markers:
...     print(marker.reference.location)

2019-04-10 10:43:07 None
2019-04-10 10:43:07 None
2019-04-10 10:43:07 None
2019-04-10 10:43:07 Vector([0.6, 0.375, 0.0])
2019-04-10 10:43:07 Vector([0.0, 0.375, 0.0])
2019-04-10 10:43:07 Vector([0.6, 0.0, 0.0])
2019-04-10 10:43:07 Vector([0.0, 0.0, 0.0])

Printing the position of the markers:
Code: [Select]
>>> chunk = Metashape.app.document.chunks[0]
>>> for marker in chunk.markers:
... print(marker.position)
...
2019-04-10 10:52:15 Vector([-1.4113132307602854, 0.0882688990110554, -4.452523572010532])
2019-04-10 10:52:15 Vector([-0.5591181822734794, 0.1058108623840947, -4.584972387400069])
2019-04-10 10:52:15 Vector([-0.9319427602606366, 0.0550744033151845, -4.512162225800721])
2019-04-10 10:52:15 Vector([-0.15048646230572668, 0.7777740724289381, -4.722076031239419])
2019-04-10 10:52:15 Vector([-2.1146734883026497, 0.6626549568104686, -4.627042682200283])
2019-04-10 10:52:15 Vector([-0.06550919103603609, -0.4980640313039025, -4.633104942878641])
2019-04-10 10:52:15 Vector([-2.044947801323979, -0.6179052161781581, -4.544628735583648])
>>>



Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Access estimated location of markers through Python
« Reply #1 on: April 10, 2019, 12:35:19 PM »
Hello Kaspar,

If the chunk is referenced/scaled you need to apply the chunk.transformation matrix to the marker position values derived from Python, as they are in the internal coordinate system.

Code: [Select]
chunk = Metashape.app.document.chunks[0]
for marker in chunk.markers:
  print(chunk.transform.matrix.mulp(marker.position))
Best regards,
Alexey Pasumansky,
Agisoft LLC

jslyder

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Access estimated location of markers through Python
« Reply #2 on: April 09, 2021, 11:51:49 PM »
Has something changed in the Python API in version 1.7.1 that would make this solution not work for accessing the estimated marker coordinates via the console?  I was trying to run this on a project, and the estimated values from the script are very different from what I see in the reference panel.  A screenshot with the estimated values from one marker "IS9" from the reference panel and what the script prints is attached for comparison. 

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: Access estimated location of markers through Python
« Reply #3 on: April 10, 2021, 01:45:00 AM »
Hi jslyder,

in the example your chunk is referenced in some sort of projected UTM CRS. So chunk.transform.matrix.mulp(marker.position) will give you coodinates in geocentric CRS (ecef) and to get the coordinates of your markers in the chunk crs you must do:

 
Code: [Select]
chunk = Metashape.app.document.chunks[0]
for marker in chunk.markers:
  print(chunk.crs.project(chunk.transform.matrix.mulp(marker.position)))

« Last Edit: April 10, 2021, 08:00:04 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

jslyder

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Access estimated location of markers through Python
« Reply #4 on: April 12, 2021, 02:29:31 PM »
Paulo,

Thank you, that work perfectly.