Forum

Author Topic: Write marker image coordinates and crs file coordinates to textfile  (Read 4976 times)

mkol

  • Newbie
  • *
  • Posts: 1
    • View Profile
Hi

I'm trying to export the image coordinates and coordinates in a projected reference system for each marker to one text file. I started piecing together some bits of code from around the forum but I am having some trouble. My plan in the code below is to write two text files (one with img coordinates, one with reference system coordinates) and then piece them together in pandas.

The first bit is moving along fine.

Here's the code so far:

Code: [Select]
path = r"path\to\project\folder"
f_img = open(path + "\img_coords.txt", 'wt')

f_img.write("camera_label, " + "marker_label, " + "x, " + "y, " + "key" + "\n")

for camera in chunk.cameras:

    for marker in chunk.markers:
        if not marker.projections[camera]:
            key = 0
            x0, y0 = camera.project(marker.position)
        else:
            key = 1
            x0, y0 = marker.projections[camera].coord
            f_img.write("{}, {}, {:.4f}, {:.4f}, {}".format(camera.label, marker.label, x0, y0, key) + "\n")


f_img.close()

f_gcp = open(path + "\gcp_coords.txt", "wt")
f_gcp.write("camera_label, " + "marker_label, " + "x_crs, " + "y_crs, " + "\n")

# Loop for writing to file:


f_gcp.close()
print("Finished")

I guess there is a much more elegant way to do this but I am struggling a little with the api documentation. Some tutorials to help understand the structure would be much appreciated!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15660
    • View Profile
Re: Write marker image coordinates and crs file coordinates to textfile
« Reply #1 on: June 20, 2019, 09:09:26 PM »
Hello mkol,

If you need to get the 2D coordinates of the marker's projection on the image and the 3D location of the marker in the space (geographic system), use the following code as a reference:
Code: [Select]
x_img, y_img = marker.projections[camera].coord
x_geog, y_geog, z_geog = chunk.crs.project(chunk.transform.matrix.mulp(marker.position))

The second line gives you the estimated position of the marker in geographic coordinates, like you see it in the Reference pane -> Estimated values tab.
Best regards,
Alexey Pasumansky,
Agisoft LLC