Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started by: pts_and_clouds on July 21, 2022, 02:42:33 PM
-
I have a single image (actually a Metashape Orthophoto) which has some markers that I can run marker detection on. All I want are the pixel coordinates of these markers, but I cannot use the markers.projections approach because there is no alignment to speak of here and projections returns None.
I tried to export the markers to an XML file (below) and sure enough, I can see the locations of two markers in pixel coordinates towards the end of the file. How do I recover these using the Python API?
Thank you.
---------------------
<?xml version="1.0" encoding="UTF-8"?>
<document version="1.5.0">
<chunk label="Chunk 1" enabled="true">
<sensors next_id="1">
<sensor id="0" label="unknown" type="frame">
<resolution width="3038" height="3561"/>
<property name="layer_index" value="0"/>
<bands>
<band label="Red"/>
<band label="Green"/>
<band label="Blue"/>
</bands>
<data_type>uint16</data_type>
</sensor>
</sensors>
<components next_id="0"/>
<cameras next_id="1" next_group_id="0">
<camera id="0" sensor_id="0" label="Austin_6_24_2_test_pib-bchudzsz"/>
</cameras>
<markers next_id="2" next_group_id="0">
<marker id="0" label="target 116"/>
<marker id="1" label="target 117"/>
</markers>
<reference>LOCAL_CS["Local Coordinates (m)",LOCAL_DATUM["Local Datum",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]]]</reference>
<settings>
<property name="accuracy_tiepoints" value="1"/>
<property name="accuracy_cameras" value="10"/>
<property name="accuracy_cameras_ypr" value="10"/>
<property name="accuracy_markers" value="0.0050000000000000001"/>
<property name="accuracy_scalebars" value="0.001"/>
<property name="accuracy_projections" value="0.5"/>
</settings>
<frames next_id="1">
<frame id="0">
<markers>
<marker marker_id="0">
<location camera_id="0" pinned="true" x="2619.54663" y="1992.58142"/>
</marker>
<marker marker_id="1">
<location camera_id="0" pinned="true" x="2820.41455" y="2001.7561"/>
</marker>
</markers>
</frame>
</frames>
</chunk>
</document>
-
Hello,
given your marker m did you try this:
for camera in m.projections.keys():
print(camera.label,m.projections[camera].coord.x,m.projections[camera].coord.y)
-
Thanks, that worked!
I thought I had tried this before, but I guess I didn't do it right. ;D
-
@Paulo,
What I want to do ultimately is to read the coordinates of each marker in each image and divide them by 2, but it looks like marker coordinates are not changeable. The following commands produce no change in the coordinates:
m.projections[cam].coord.x /= 2.0
m.projections[cam].coord.y /= 2.0
Do you know of any workaround to this?
-
Maybe following could work:
new_coord = m.projections[cam].coord / 2
m.projections[cam].coord = new_coord
-
Worked again, thanks!