Forum

Author Topic: Changing coordinate system on all cameras  (Read 9036 times)

BarryReid

  • Newbie
  • *
  • Posts: 15
    • View Profile
Changing coordinate system on all cameras
« on: June 11, 2015, 05:05:20 AM »
Hi there

I'm trying to figure out how to convert the coordinate system on all cameras using the API.

I have tried something like this

Code: [Select]
crs = app.getCoordinateSystem("Select project coordinate system")
chunk.crs = crs

But that changes the project coordinate system but does not convert the cameras projection from the old to the new.

I just want it to do the same thing as hitting the convert button on the camera reference tab.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15086
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #1 on: June 11, 2015, 08:08:53 PM »
Hello Barry,

In order to convert coordinates for system based on the same Datum, you need to unproject coordinates using the first coordinate system and then project using the second one:

Code: [Select]
coord = PhotoScan.Vector([X, Y, Z])
crs = PhotoScan.CoordinateSystem("EPSG::...")
crs_new = PhotoScan.CoordinateSystem("EPSG::...")

coord = crs.unproject(coord)
coord = crs_new.project(coord)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Emanuele1234

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #2 on: March 17, 2021, 06:59:49 PM »
I'm sorry, I don't understand well the Vector part! what are X, Y, Z and where I can find these, for example in an opened project with metashape?

Because I trying to change the crs by scripts on a Metashape project, but I don't understand this part! I'm sorry for bother!

Thank you in advance,
Best regards,
Emanuele.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15086
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #3 on: March 17, 2021, 09:16:49 PM »
Hello Emanuele,

Please check the following code:

Code: [Select]

source_crs = PhotoScan.CoordinateSystem("EPSG::4326")
target_crs = PhotoScan.CoordinateSystem("EPSG::32623")
chunk = Metashape.app.document.chunk
for camera in chunk.camers:
    if not camera.reference.location:   
        continue
    camera.reference.location = Metashape.CoordinateSystem.transform(camera.reference.location, source_crs, target_crs)

Best regards,
Alexey Pasumansky,
Agisoft LLC

Emanuele1234

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #4 on: March 18, 2021, 12:57:57 PM »
Hi Alexy, thank you for your support!

I made the wrong question probably before, so I need to ask you now another thing.

What I mean is: How I can get the vector coordinates normally? Because I work in pycharm so I usually don't open Agisoft Metashape for this elaborations.

So, my question is, if I need to change e camera and project crs, where I can find vector coordinates? In more, I tried both the method, but when I open for check agisoft and the project, and I go on the calculator icon on reference, I see that the crs is not change! It is normal?
Sorry for the questions, I want only understand how to work this things!

Paulo

  • Hero Member
  • *****
  • Posts: 1354
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #5 on: March 18, 2021, 01:56:56 PM »
Hello Emanuele,

as specified by Alexey, let us say you have your cameras referenced in WGS84 CRS (chunk.crs) and want to convert them to WGS84/ UTM zone 6 N ("EPSG::32606") then following code will do the trick:
Code: [Select]
chunk = Metashape.app.document.chunk
source_crs = chunk.crs # WGS84
target_crs = PhotoScan.CoordinateSystem("EPSG::32606") # WGS84/UTM06 N
for camera in chunk.cameras:
    if not camera.reference.location:   
        continue
    print("Source Coordinates for",camera.label,":",camera.reference.location," in",source_crs.name)
    camera.reference.location = Metashape.CoordinateSystem.transform(camera.reference.location, source_crs, target_crs)
    print("Target Coordinates for",camera.label,":",camera.reference.location," in",target_crs.name)
chunk.crs = target_crs

and the printed output would be as:
Code: [Select]
2021-03-18 06:03:11 Source Coordinates for DJI_0357.tiff : Vector([-147.858200000127, 64.8554152780109, 248.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0357.tiff : Vector([459312.5123923809, 7192616.907659786, 248.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0359.tiff : Vector([-147.858108611107, 64.85547638893128, 247.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0359.tiff : Vector([459316.93729799363, 7192623.658982667, 247.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0361.tiff : Vector([-147.858062777519, 64.85551444424524, 248.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0361.tiff : Vector([459319.1676681044, 7192627.870324763, 248.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0363.tiff : Vector([-147.858047500187, 64.85552222198912, 247.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0363.tiff : Vector([459319.903684075, 7192628.727240421, 247.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0365.tiff : Vector([-147.85801694446104, 64.85552222198912, 247.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0365.tiff : Vector([459321.3522641624, 7192628.707601423, 247.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0367.tiff : Vector([-147.857864444521, 64.8555069446563, 248.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0367.tiff : Vector([459328.558876019, 7192626.907122786, 248.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0369.tiff : Vector([-147.857681388855, 64.85549916691251, 247.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0369.tiff : Vector([459337.2254038893, 7192625.922768301, 247.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0371.tiff : Vector([-147.857528611289, 64.8554916667938, 247.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0371.tiff : Vector([459344.45693601645, 7192624.988825623, 247.0])  in WGS 84 / UTM zone 6N
2021-03-18 06:03:11 Source Coordinates for DJI_0373.tiff : Vector([-147.857345555623, 64.85548388905, 247.0])  in WGS 84
2021-03-18 06:03:11 Target Coordinates for DJI_0373.tiff : Vector([459353.1234738997, 7192624.0045170905, 247.0])  in WGS 84 / UTM zone 6N

Hope this clears uo your doubts,
« Last Edit: March 18, 2021, 03:06:09 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

antoine billault

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #6 on: May 03, 2023, 01:04:10 AM »
hello Paul,
I wanted to follow up that previous reply

but I would like to slighlty change it :
I wanted to apply GNSS leverarm before printing source and target coordinates.

I already setup camera.sensor as well as camera.antenna.rerefence vector
something like that
sensor.antenna.location_ref = Metashape.Vector([0.000, -0.005, 0.068])

so how to apply GNSS leverarm ? If I am not wrong, GNSS leverarm vector is given in camera ref system model.
I understand we must work in LSE (Local Space Euclidean coordinate system) if my source coordinate are given in geographic coord (lat ; long ; ellipsoid height)

So should I do that in 2 steps ?
express antenna leverarm in LSE
apply conversion from lat,long,ellip_h into LSE ?

also , is chunk.updateTransform() needed after step 1 ? step 2 ?

thx
antoine

Paulo

  • Hero Member
  • *****
  • Posts: 1354
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #7 on: May 03, 2023, 03:52:33 AM »
Halo Antoine,

Given T = chunk.transform.matrix,
AR  = camera.sensor.antenna.location_ref # antenna reference lever arm
and CT = camera.transform for a given camera, then the camera center reference coordinates in ecef CS are:

 CC = chunk.crs.unproject(camera.reference.location)
and  CC - (T*CT).rotation() * Metashape.Matrix.Diag((1, -1, -1)) * AR is camera center ecef coordinates with antenna offset applied 
 
for target crs the coordinates are target_crs.project(CC - (T*CT).rotation() * Metashape.Matrix.Diag((1, -1, -1)) *AR) or Metashape.CoordinateSystem.transform(CC - (T*CT).rotation() * Metashape.Matrix.Diag((1, -1, -1)) *AR, ecef_crs, target_crs)

Hope this makes  sense,

PS. look at https://github.com/agisoft-llc/metashape-scripts/blob/master/src/save_estimated_reference.py where get_AntennaTransform() shows how to apply lever arm and boresight to coordinates
« Last Edit: May 03, 2023, 04:17:35 AM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

antoine billault

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Changing coordinate system on all cameras
« Reply #8 on: May 11, 2023, 07:03:45 PM »
thank you Paul for that reply.

I am not sure I understand the  Metashape.Matrix.Diag((1, -1, -1) ... whereas on other post on the same topic it's a 4x4 matrix being used such as  Metashape.Matrix.Diag((1, -1, -1, 1)

by the way, that post https://www.agisoft.com/forum/index.php?topic=13611.msg60200 should also be helpful as we work with pandas as well.
with that code we can afterward discriminate sensor model as well in the DataFrame written.

antoine