Forum

Author Topic: Marker pixel location from a single image without alignment  (Read 1225 times)

pts_and_clouds

  • Newbie
  • *
  • Posts: 10
    • View Profile
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>

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Marker pixel location from a single image without alignment
« Reply #1 on: July 22, 2022, 05:22:51 PM »
Hello,

given your marker m did you try this:
Code: [Select]
for camera in m.projections.keys():
    print(camera.label,m.projections[camera].coord.x,m.projections[camera].coord.y)
Best Regards,
Paul Pelletier,
Surveyor

pts_and_clouds

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Marker pixel location from a single image without alignment
« Reply #2 on: July 22, 2022, 05:40:18 PM »
Thanks, that worked!

I thought I had tried this before, but I guess I didn't do it right.   ;D

pts_and_clouds

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Marker pixel location from a single image without alignment
« Reply #3 on: July 25, 2022, 10:07:43 AM »
@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:

Code: [Select]
m.projections[cam].coord.x /= 2.0
m.projections[cam].coord.y /= 2.0

Do you know of any workaround to this?

Paulo

  • Hero Member
  • *****
  • Posts: 1320
    • View Profile
Re: Marker pixel location from a single image without alignment
« Reply #4 on: July 25, 2022, 03:37:16 PM »
Maybe following could work:
Code: [Select]
new_coord = m.projections[cam].coord / 2
m.projections[cam].coord = new_coord
Best Regards,
Paul Pelletier,
Surveyor

pts_and_clouds

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Marker pixel location from a single image without alignment
« Reply #5 on: July 26, 2022, 07:26:37 AM »
Worked again, thanks!