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:
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)