Agisoft Metashape

Agisoft Metashape => General => Topic started by: dellagiu on May 28, 2015, 03:29:15 AM

Title: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: dellagiu on May 28, 2015, 03:29:15 AM
I have Euler angles (omega, phi, and kappa) for camera position, but I see that Photoscan requires Yaw, Pitch, & Roll. See the attached image for reference of how these Euler angles are defined.

I have exported these values from SOCET SET as:
omega           3.137187395607711
phi               -11.083974477310051
kappa           17.113750627601377

After spending sometime online, it is still not clear to me how to make this conversion. Can someone point me in the right direction? What conventions does PhotoScan Pro use to define Yaw, Pitch, & Roll?
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on May 29, 2015, 03:40:59 PM
Hello dellagiu,

Using the following script you should be able to generate camera transformation matrix from OPK data:


Code: [Select]
import math, PhotoScan

#omega, phi, kappa - in radians
#X, Y, Z - coordinate information about camera position in units of the corresponding coordinate system


T = chunk.transform.matrix
v_t = T * PhotoScan.Vector( [0, 0, 0, 1] )
v_t.size = 3
m = chunk.crs.localframe(v_t)
m = m * T
s = math.sqrt(m[0, 0] **2 + m[0,1] **2 + m[0,2] **2) #scale factor

sina = math.sin(0 - omega)
cosa = math.cos(0 - omega)
Rx = PhotoScan.Matrix([[1, 0, 0], [0, cosa, -sina], [0, sina, cosa]])
sina = math.sin(0 - phi)
cosa = math.cos(0 - phi)
Ry = PhotoScan.Matrix([[cosa, 0, sina], [0, 1, 0], [-sina, 0, cosa]])
sina = math.sin(0 - kappa)
cosa = math.cos(0 - kappa)
Rz = PhotoScan.Matrix([[cosa, -sina, 0], [sina, cosa, 0], [0, 0, 1]])
 

t = PhotoScan.Vector([X, Y, Z])
t = chunk.crs.unproject(t)

m = chunk.crs.localframe(t)
m = PhotoScan.Matrix([ [m[0,0], m[0,1], m[0,2]], [m[1,0], m[1,1], m[1,2]], [m[2,0], m[2,1], m[2,2]] ])


R = m.inv() * (Rz * Ry * Rx).t()  * PhotoScan.Matrix().diag([1, -1, -1])

Tr = PhotoScan.Matrix([ [R[0,0], R[0,1], R[0,2], t.x], [R[1,0], R[1,1], R[1,2], t.y], [R[2,0], R[2,1], R[2,2], t.z], [0, 0, 0, 1]])

camera.transform = chunk.transform.matrix.inv() * Tr * (1. / s)
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on May 29, 2015, 03:46:33 PM
And then to get yaw, pitch, roll angles from camera transform you can use the following:

Code: [Select]
v_t = T.mulp(camera.center)
m = chunk.crs.localframe(v_t)

R = m * T * camera.transform * PhotoScan.Matrix().diag([1, -1, -1, 1])
row = list()
for j in range (0, 3):
row.append(R.row(j))
row[j].size = 3
row[j].normalize()
R = PhotoScan.Matrix([row[0], row[1], row[2]])

if R[2, 1] > 0.999:
yaw = math.atan2(R[1, 0], R[0, 0])
pitch = math.pi / 2
roll = 0
elif R[2, 1] < -0.999:
yaw = math.atan2(R[1, 0], R[0, 0])
pitch = -math.pi / 2
roll = 0
else:
yaw = math.atan2(-R[0, 1], R[1, 1])
roll = math.atan2(-R[2, 0], R[2, 2])
pitch  = math.asin(R[2, 1])

if yaw > 0:
yaw -= 2 * math.pi

yaw = -180 / math.pi
pitch *= 180 / math.pi
roll *= 180 / math.pi
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Diego on May 29, 2015, 11:25:16 PM
Hi Alexey,

But these angles actually used in the adjustment?, if so, then why not work directly with omega, phi and kappa, which is the standard for photogrammetry?, this really improve the accuracy of triangulation for those who work with data GNSS/IMU high precision.

Test scripts to generate an error, that requirement is to be used?

Best regards,

Diego
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: dellagiu on May 30, 2015, 01:28:30 AM
Thank you Alexey -- this code is helpful.

I am also interested in Diego's question.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on May 30, 2015, 11:29:39 AM
Hello Diego,

If the angles are loaded to the Reference pane, they are not used for alignment process (only for pair preselection, if Ground Altitude is defined in the Reference pane settings).
But the provided code can be used to apply existing extrinsic orientation to position camera, if additionally the camera calibration is loaded it is possible to Build Point cloud via Tools Menu or Python. It means that the camera positions wouldn't be adjusted by PhotoScan. But such approach is only applicable if the positions and orientation angles are known precisely.
So actually the code works as a part of Import Cameras functionality related to the extrinsic orientation only.


camera and chunk variables should be defined before using the code. Also for the first script XYZ and OPK should be defined.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: dellagiu on June 10, 2015, 12:27:35 AM
Hi Alexey,

I have tried to use your script, and have also read through the most recent documentation for the PhotoScan Python API. I get the following error when running this code:

Traceback (most recent call last):
  File "/Users/dellagiu/Desktop/photoscan_ypr.py", line 7, in <module>
    T = chunk.transform.matrix
NameError: name 'chunk' is not defined
>>>

I have defined the "chunk" using the name of my photo chunk, but still continue to get this error. Please advise
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on June 10, 2015, 01:20:07 PM
Hello dellagiu,

Chunk can be defined by its number (leading zero) in the document like
chunk = doc.chunks[3], where doc = PhotoScan.app.document

But or active chunk you can use chunk = doc.chunk assignment.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Roy on April 10, 2016, 02:21:47 PM
Hi alexey.

i'm wondering what is the difference between the script you added to this topic (conversion from opk to ypr)
to the script you once wrote in a different topic in which you wrote that using the following code transform from opk to ypr

yaw, pitch, roll = PhotoScan.utils.mat2ypr(PhotoScan.utils.opk2mat(PhotoScan.Vector((omega, phi, kappa))).t())

what is the difference?
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on April 10, 2016, 02:26:04 PM
Hello Roy,

opk2mat and mat2ypr functions were added to Python API only recently.

Also I'd like to note that in case you need to take into account the meridian convergence, the script may be a little bit more complicated.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: uop360 on April 11, 2016, 01:17:51 PM
Could you please provide a full script?
I managed to add at the beginning:
import math, PhotoScan

doc = PhotoScan.app.document
chunk = doc.chunk

but there is still problem with line 16:
sina = math.sin(0 - omega)
2016-04-11 12:08:39 NameError: name 'omega' is not defined

 


Hello dellagiu,

Using the following script you should be able to generate camera transformation matrix from OPK data:


Code: [Select]
import math, PhotoScan

#omega, phi, kappa - in radians
#X, Y, Z - coordinate information about camera position in units of the corresponding coordinate system


T = chunk.transform.matrix
v_t = T * PhotoScan.Vector( [0, 0, 0, 1] )
v_t.size = 3
m = chunk.crs.localframe(v_t)
m = m * T
s = math.sqrt(m[0, 0] **2 + m[0,1] **2 + m[0,2] **2) #scale factor

sina = math.sin(0 - omega)
cosa = math.cos(0 - omega)
Rx = PhotoScan.Matrix([[1, 0, 0], [0, cosa, -sina], [0, sina, cosa]])
sina = math.sin(0 - phi)
cosa = math.cos(0 - phi)
Ry = PhotoScan.Matrix([[cosa, 0, sina], [0, 1, 0], [-sina, 0, cosa]])
sina = math.sin(0 - kappa)
cosa = math.cos(0 - kappa)
Rz = PhotoScan.Matrix([[cosa, -sina, 0], [sina, cosa, 0], [0, 0, 1]])
 

t = PhotoScan.Vector([X, Y, Z])
t = chunk.crs.unproject(t)

m = chunk.crs.localframe(t)
m = PhotoScan.Matrix([ [m[0,0], m[0,1], m[0,2]], [m[1,0], m[1,1], m[1,2]], [m[2,0], m[2,1], m[2,2]] ])


R = m.inv() * (Rz * Ry * Rx).t()  * PhotoScan.Matrix().diag([1, -1, -1])

Tr = PhotoScan.Matrix([ [R[0,0], R[0,1], R[0,2], t.x], [R[1,0], R[1,1], R[1,2], t.y], [R[2,0], R[2,1], R[2,2], t.z], [0, 0, 0, 1]])

camera.transform = chunk.transform.matrix.inv() * Tr * (1. / s)
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Vitalijus on October 20, 2016, 02:34:08 PM
Hey Alexej,

I just started testing Agisoft. We are Surveying-engineering company. Could you explain in a simple manner how to transform OPK degrees to YPR angles? I have no programming skills, how do you run that script?

Thank you!

Best,
Vitalijus

Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on October 20, 2016, 02:56:10 PM
Hello Vitalijus,

You can use the following function Python function from the Console pane to load the reference data using OPK data:
Code: [Select]
PhotoScan.app.document.chunk.importCameras(path = "d:/file.txt", format = "opk")At the moment, .importCameras() Python API function assumes that each line contains the following information in the same order:
Quote
camera_label x-coord y-coord z-coord omega phi kappa

So using this function (with the proper filepath, of course) will automatically convert OPK angles and load them to the Reference pane as YPR.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: lena on June 07, 2017, 02:16:23 PM
hallo!
I just wrote in console this script
PhotoScan.app.document.chunk.importCameras(path = "d:/e:/Arbeit/Sellin/5_Berechnung-3D/RNY.txt", format = "opk")
the pass is right for sure
but it stil cant run script
I am doing it through
<>run python script
and direct from console it also doesnt work
My photoscan version is  1.2.6


Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on June 07, 2017, 03:02:38 PM
Hello lena,

I suggest to double check the path, for me "d:/e:/" looks strange.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: lena on June 10, 2017, 10:42:22 AM
sorry it was my mistake (
but now I have PhotoScan.app.document.chunk.importCameras(path = "c:/studing/germany/diplomaITN/RNY.txt", format = "opk")
error  TypeError: argument 2 must be PhotoScan.CamerasFormat, not str
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Alexey Pasumansky on June 10, 2017, 06:11:59 PM
Hello lena,

If you have switched to the version 1.3.2, you can just use Import CSV dialog from GUI and choose omega, phi, kappe angle convention.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Gwen_sl on June 27, 2018, 10:47:12 AM
Hello Vitalijus,

You can use the following function Python function from the Console pane to load the reference data using OPK data:
Code: [Select]
PhotoScan.app.document.chunk.importCameras(path = "d:/file.txt", format = "opk")At the moment, .importCameras() Python API function assumes that each line contains the following information in the same order:
Quote
camera_label x-coord y-coord z-coord omega phi kappa

So using this function (with the proper filepath, of course) will automatically convert OPK angles and load them to the Reference pane as YPR.


Hello Alexey, does this work on the 1.2.6 version of PhotoScan ?
I ran the line throught the console, the process finished but I don't see any result... nothing load to the reference pane
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: lfreguete on June 24, 2021, 11:00:27 PM
I am having hte same problem here.
I had a file imported from Pix4D with all the coordinates of the calibrated cameras. However, the camera orientation are in opk.
I tried to use this solution
yaw, pitch, roll = PhotoScan.utils.mat2ypr(PhotoScan.utils.opk2mat(Metashape.Vector((omega, phi, kappa))).t())

but the resulting angles are way far from what is expected to be. I am trying the solution form this topic now, but having issues with it (error message in the attachments)
Omega is a list of all the cameras' omegas or just one value?


Hello dellagiu,

Using the following script you should be able to generate camera transformation matrix from OPK data:


Code: [Select]
import math, PhotoScan

#omega, phi, kappa - in radians
#X, Y, Z - coordinate information about camera position in units of the corresponding coordinate system


T = chunk.transform.matrix
v_t = T * PhotoScan.Vector( [0, 0, 0, 1] )
v_t.size = 3
m = chunk.crs.localframe(v_t)
m = m * T
s = math.sqrt(m[0, 0] **2 + m[0,1] **2 + m[0,2] **2) #scale factor

sina = math.sin(0 - omega)
cosa = math.cos(0 - omega)
Rx = PhotoScan.Matrix([[1, 0, 0], [0, cosa, -sina], [0, sina, cosa]])
sina = math.sin(0 - phi)
cosa = math.cos(0 - phi)
Ry = PhotoScan.Matrix([[cosa, 0, sina], [0, 1, 0], [-sina, 0, cosa]])
sina = math.sin(0 - kappa)
cosa = math.cos(0 - kappa)
Rz = PhotoScan.Matrix([[cosa, -sina, 0], [sina, cosa, 0], [0, 0, 1]])
 

t = PhotoScan.Vector([X, Y, Z])
t = chunk.crs.unproject(t)

m = chunk.crs.localframe(t)
m = PhotoScan.Matrix([ [m[0,0], m[0,1], m[0,2]], [m[1,0], m[1,1], m[1,2]], [m[2,0], m[2,1], m[2,2]] ])


R = m.inv() * (Rz * Ry * Rx).t()  * PhotoScan.Matrix().diag([1, -1, -1])

Tr = PhotoScan.Matrix([ [R[0,0], R[0,1], R[0,2], t.x], [R[1,0], R[1,1], R[1,2], t.y], [R[2,0], R[2,1], R[2,2], t.z], [0, 0, 0, 1]])

camera.transform = chunk.transform.matrix.inv() * Tr * (1. / s)
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Paulo on June 25, 2021, 03:51:52 AM
Hi lfreguete,

if you have a file from Pix4D with calibrated external camera parameters with following format (imageName X Y Z Omega Phi Kappa):
Code: [Select]
imageName X Y Z Omega Phi Kappa
DJI_0002.JPG 486862.202652 2626448.858317 332.437667 19.519819 -3.285101 -9.034320
DJI_0003.JPG 486863.093666 2626460.003104 332.686111 19.595224 -4.117747 -10.382848
DJI_0004.JPG 486864.173630 2626477.601380 333.275810 19.698628 -3.958097 -9.997219
DJI_0005.JPG 486865.410026 2626495.172434 333.694031 19.657402 -4.120313 -10.610904
DJI_0006.JPG 486866.539559 2626513.363608 333.610094 19.601182 -4.326155 -11.133216
DJI_0007.JPG 486866.364116 2626516.853950 332.856768 0.254071 -19.187457 -89.557675
DJI_0008.JPG 486874.845835 2626515.362043 332.100779 -3.662028 -19.171621 -99.991631
DJI_0009.JPG 486892.509257 2626513.608562 332.517719 -4.123422 -19.251533 -100.363356
DJI_0010.JPG 486896.622590 2626512.994224 332.621008 -19.643082 2.991298 171.805297
DJI_0011.JPG 486895.363848 2626503.405120 331.978818 -19.963121 3.830133 171.362829
DJI_0012.JPG 486893.844702 2626485.680885 331.834505 -20.021977 3.795313 171.967951

then you can use folowing command to set angle definition to OPK
Code: [Select]
Metashape.app.document.chunk.euler_angles = Metashape.EulerAngles.EulerAnglesOPKbefore using chunk.importReference() to import above file and orientation angles will all be taken into account as OPK...

see following attachment....

Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: lfreguete on June 25, 2021, 04:23:24 AM
Good evening, Mr. Pelletier.

Thank you for your suggestion.
My situation is the following: I was able to import the cameras' external parameters file and have the orientation angles as OPK. But for the next steps of my workflow, I need those angles in YPK.
I used the function yaw, pitch, roll = Metashape.utils.mat2ypr(Metashape.utils.opk2mat(Metashape.Vector((omega, phi, kappa))).t()) but I am not very sure the outputs are right,
For example, when importing the images, the first camera presents a Ywas = 142 while the output from this conversion gives 124. I know that the first yaw value is before the camera optimization, but even though it shouldn't have such a difference. Should it?

Is this the correct way to go?

Thanks a lot.
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Paulo on June 25, 2021, 05:59:26 AM
Ok,

if you have your camera reference rotation in OPK format and want to convert to YPR then following code would do this for all cameras in chunk (including applying grid convergence for Transverse Mercator Projected CS):
Code: [Select]
crs = chunk.crs # CRS ("EPSG::32614") UTM 14
cm = -99 # central meridian of Transverse mercator projection  ("EPSG::32614")
for c in chunk.cameras:
    pg = crs.transform(c.reference.location, crs, crs.geogcs) # camera center in geographic CS
    gc = math.atan(-math.sin(pg.y/180*math.pi)*math.tan((pg.x-(cm))/180*math.pi))/math.pi*180 # grid convergence in degrees
    c.reference.rotation = Metashape.utils.mat2ypr(Metashape.utils.opk2mat(c.reference.rotation)) - Metashape.Vector((gc,0,0))

chunk.euler_angles = Metashape.EulerAngles.EulerAnglesYPR

Hope this helps,

PS you had a .t() (transpose of Metashape.utils.opk2mat() Matrix) which produced the error in your formula
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: lfreguete on June 26, 2021, 04:33:16 AM
I actually found another way of solving it. This way I was able to import the cameras coordinates and convert the opk to ypr.
Here I am sharing a snippet of the code

##APLYING CONVERSION OPK2PYR
chunk.euler_angles = Metashape.EulerAngles.EulerAnglesOPK
# chunk.importCameras(path = os.path.join(path,filename), format = Metashape.CamerasFormatOPK)
crs = Metashape.CoordinateSystem("EPSG::6440")
chunk.crs = crs
chunk.importReference(path=os.path.join(path,filename), format=Metashape.ReferenceFormatCSV, columns='nxyzabc', crs = crs, delimiter=' ', create_markers=False)

for c in chunk.cameras:
    c.reference.rotation = Metashape.utils.mat2ypr(Metashape.utils.opk2mat(c.reference.rotation))   
    c.reference.location = c.reference.location


Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Paulo on June 26, 2021, 05:58:00 AM
Hi lfreguete,

the code you shared does not take into account grid convergence for your LCC crs.... to take this into account and thus conform with using the GUI Reference pane convert button to transform from Omega, Phi, Kappa rotation angles to Yaw, Pitch, Roll I would use following snippet:
Code: [Select]
crs = chunk.crs #  CRS("EPSG::6440")
cm = -84.5 # central meridian of projection ("EPSG::6440")
phi0 = 29 # latitude of origin of projection ("EPSG::6440")
for c in chunk.cameras:
    pg = crs.transform(c.reference.location, crs, crs.geogcs) # camera center in geographic CS
    if cm < 0: #Western Hemisphere
        gc = (cm - pg.x)*math.sin(phi0/180*math.pi) # grid convergence in degrees
    else: #Eastern Hemisphere
        gc = (pg.x - cm)*math.sin(phi0/180*math.pi) # grid convergence in degrees
    c.reference.rotation = Metashape.utils.mat2ypr(Metashape.utils.opk2mat(c.reference.rotation)) - Metashape.Vector((gc,0,0))
chunk.euler_angles = Metashape.EulerAngles.EulerAnglesYPR
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: lfreguete on June 26, 2021, 06:23:55 AM
Do you mind if I share here the files I have gotten so far with the current code?
The ypk output I got seem to be reasonable. I am not familiar with the metashape functions so I am not sure what is the math behind the Metashape.utils.mat2ypr(Metashape.utils.opk2mat(c.reference.rotation)) .
From the manual, I got that opk2mat calculates to world rotation values, but I am not sure if this takes on account the defined crs ( as it is done in the code) or if it considers a default crs.
Would you know more details about it?

Here I am sharing the input,output and code files.


Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Paulo on June 26, 2021, 08:49:10 AM
Yes freguete,

the formula you use basically transforms from OPK to YPR angle format except for yaw as it does not account for grid convergence. I took your original input file and adapted it to a set of 46 images I have by changing the camera labels as :
Code: [Select]
camera_label x-coord y-coord z-coord omega phi kappa
DJI_0002.JPG 565913.846998 74514.171977 -0.657877 -21.028216 21.843247 136.042348
DJI_0003.JPG 565910.080575 74511.003873 -0.288412 -21.380630 21.681882 136.641800
DJI_0004.JPG 565906.363962 74507.794833 -0.358439 -21.306807 21.878936 136.148183
DJI_0005.JPG 565902.260776 74504.865416 -0.481662 -21.160047 22.118499 135.547627
DJI_0006.JPG 565898.224392 74501.820554 -0.392458 -21.689193 21.712659 136.759011
DJI_0007.JPG 565894.457041 74498.661131 -0.470489 -21.349519 22.132705 135.688980
DJI_0008.JPG 565890.589424 74495.650935 -0.676629 -21.379259 22.167888 135.624986
DJI_0009.JPG 565886.460579 74492.673041 -0.595070 -21.602013 21.977819 136.188767
DJI_0010.JPG 565882.538302 74489.481247 -0.242720 -21.550776 22.054879 135.906153
DJI_0011.JPG 565878.567562 74486.685286 -0.290945 -21.697483 21.963246 136.208336
DJI_0012.JPG 565874.602135 74483.630432 -0.447463 -21.911418 21.770636 136.668871
DJI_0013.JPG 565870.826706 74480.461558 -0.777970 -22.060916 21.584828 137.189448
DJI_0014.JPG 565866.834995 74477.410824 -0.952921 -21.848278 21.775524 136.570056
DJI_0015.JPG 565862.834631 74474.253236 -1.008897 -22.011916 21.556954 137.119008
DJI_0016.JPG 565858.818229 74471.158883 -0.909844 -22.181409 21.386093 137.517229
DJI_0017.JPG 565854.935664 74468.116299 -1.103492 -22.170659 21.375316 137.479798
DJI_0018.JPG 565850.566758 74466.541319 -1.311738 -8.081117 28.974924 105.324993
DJI_0020.JPG 565851.104513 74474.579004 -1.740644 22.572490 -19.670639 -37.676510
DJI_0021.JPG 565854.921899 74477.600035 -1.659055 20.860966 -21.775399 -43.064911
DJI_0022.JPG 565858.829298 74480.596110 -1.641437 20.803613 -22.096242 -43.706114
DJI_0023.JPG 565862.858255 74483.614675 -1.689442 20.742128 -22.295139 -44.131851
DJI_0024.JPG 565866.802896 74486.718947 -1.668561 20.700747 -22.477366 -44.330603
DJI_0025.JPG 565870.786147 74489.856036 -1.797701 20.647194 -22.655752 -44.712035
DJI_0026.JPG 565874.715473 74492.982431 -2.001021 20.692205 -22.746005 -44.725261
DJI_0027.JPG 565878.733281 74496.125403 -2.364634 20.735845 -22.793469 -44.714021
DJI_0028.JPG 565882.786222 74499.178371 -2.486617 20.795541 -22.781591 -44.759832
DJI_0029.JPG 565886.758338 74502.315182 -2.536821 20.726457 -22.911718 -44.969943
DJI_0030.JPG 565890.712469 74505.318011 -2.665926 20.817060 -22.915449 -44.835342
DJI_0031.JPG 565894.636050 74508.313332 -2.546445 20.681909 -23.093720 -45.180787
DJI_0032.JPG 565898.559073 74511.576936 -2.551850 20.768272 -23.032816 -45.107745
DJI_0033.JPG 565902.456375 74514.613226 -2.643957 20.895806 -22.949886 -44.869494
DJI_0034.JPG 565906.422417 74517.724222 -2.668356 20.981092 -22.941803 -44.832848
DJI_0035.JPG 565910.427000 74520.885262 -2.540308 20.864855 -22.898073 -44.690226
DJI_0036.JPG 565912.811810 74525.437087 -4.425587 23.245210 -18.137805 -26.325642
DJI_0038.JPG 565905.514698 74526.432652 -2.865125 -17.507351 24.018584 127.861339
DJI_0039.JPG 565901.319210 74523.557086 -2.478111 -21.044487 21.263126 136.480287
DJI_0040.JPG 565897.641480 74520.304116 -2.269319 -21.113689 21.337865 136.309846
DJI_0041.JPG 565893.553275 74517.291487 -2.121621 -21.086772 21.534844 135.981986
DJI_0042.JPG 565889.477279 74514.222810 -2.003707 -21.733681 21.054012 137.490788
DJI_0043.JPG 565885.472875 74511.127472 -1.928966 -21.882600 20.999526 137.746865
DJI_0044.JPG 565881.656016 74508.023781 -1.911717 -22.059524 21.024531 137.848303
DJI_0045.JPG 565877.758096 74504.893756 -1.965217 -22.016090 21.187286 137.690054
DJI_0046.JPG 565873.629848 74501.777767 -1.959388 -22.332511 20.957530 138.270593
DJI_0047.JPG 565869.708421 74498.586067 -1.994690 -22.338843 20.999324 138.314003
DJI_0048.JPG 565865.958894 74495.490147 -2.237834 -22.296054 21.098220 137.986118
DJI_0049.JPG 565861.878677 74492.377363 -2.096247 -21.935394 21.501432 136.807028
then i used your code (with a few changes) to importReference to these 46 cameras as OPK then transform to YPR and exportReference to a Test_ypr.txt file... see 1st attachement
But before transforming to YPR and exporting, I used Convert button from Reference pane to convert rotation angles from Omega, Phi, Kappa to Yaw, Pitch, Roll and saved  Camera reference as Test_ypr_GUI.txt.
Comparing the 2 files we see that Yaw is slightly different (about 0.18 degrees) which corresponds to grid convergence (in previous post I showed how to calculate convergence)..see 2nd attachement

Also attached 2 exported ypr files....
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: Paulo on June 27, 2021, 07:16:49 AM
Hi again,

I think I found a more elegant way to code OPK to YPR reference rotation angles transformation without using complex grid convergence formula. It corresponds to Rotation angles values transformed from Omega, Phi, Kappa to Yaw, pitch, Roll in GUI using Convert button from reference pane. The code is:
Code: [Select]
chunk = Metashape.app.document.chunk
crs = chunk.crs #  chunk Coordinate System
crsg = crs.geogcs #  chunk Geographic Coordinate System
for c in chunk.cameras:
    p = crs.unproject(c.reference.location) # camera center in geocentric coordinates (ecef)
    m = (crs.localframe(p)).rotation() # rotation transformation from ecef to crs
    m1 = (crsg.localframe(p)).rotation() # rotation transformation from ecef to crsg
    c.reference.rotation = Metashape.utils.mat2ypr(m1*m.inv()*Metashape.utils.opk2mat(c.reference.rotation))   
chunk.euler_angles = Metashape.EulerAngles.EulerAnglesYPR
and to do YPR to OPK transformation, just switch opk to ypr and m to m1 as:
Code: [Select]
chunk = Metashape.app.document.chunk
crs = chunk.crs #  chunk Coordinate System
crsg = crs.geogcs #  chunk Geographic Coordinate System
for c in chunk.cameras:
    p = crs.unproject(c.reference.location) # camera center in geocentric coordinates
    m = (crs.localframe(p)).rotation()
    m1 = (crsg.localframe(p)).rotation()
    c.reference.rotation = Metashape.utils.mat2opk(m*m1.inv()*Metashape.utils.ypr2mat(c.reference.rotation))   
chunk.euler_angles = Metashape.EulerAngles.EulerAnglesOPK
Included is your original python script adapted with correct  OPK2YPR transformation...
Hope this can be useful !
Title: Re: How to convert Euler angles to Yaw, Pitch, & Roll (what are PS's conventions?)
Post by: lfreguete on June 27, 2021, 07:47:50 PM
Ah! I see what the coding is doing.
It just uses now the transformation matrices between the 2 orientation systems.

I very much appreciate yours so throughout attention to this issue! It was a huge help indeed!