Hello!
I updated the example code to also export orientation in OPK. Unfortunately after importing the exported cameras in other software the orientation is not correct for some cameras. Compared rotation matrix and it matches in both softwares. Could it be that orientation is wrong related to fact that photos in chunk are not made with same camera model?
#export cameras coordinates and orientation as omega,phi,kappa (OPK)
#compatibility: Agisoft PhotoScan Professional 1.2.6
import PhotoScan
import math
path = PhotoScan.app.getSaveFileName("Please specify export path and filename:")
file = open(path, "wt")
#chunk = PhotoScan.app.document.activeChunk
doc = PhotoScan.app.document
chunk = doc.chunk
if chunk.transform:
#T = chunk.transform
T = chunk.transform.matrix
else:
T = PhotoScan.Matrix().diag([1,1,1,1])
print("Script started")
for camera in chunk.cameras:
if camera.transform:
coords = T.mulp(camera.center)
#x, y, z = T.mulp(camera.center)
#omega, phi, kappa = PhotoScan.utils.mat2opk(T.rotation)
m = chunk.transform.matrix * camera.transform * PhotoScan.Matrix().diag([1,-1,-1,1]) #camera transformation matrix has been multiplied by 180-degree rotation matrix, since the direction of Z axis in camera system is inverted compared to the world coordinate system.
rotation = m.rotation()
omega, phi, kappa = PhotoScan.utils.mat2opk(rotation)
print(camera.label)
print(rotation)
#print(omega, phi, kappa)
#print(x)
file.write(camera.label + "\t{:.5f}".format(coords[0]) + "\t{:.5f}".format(coords[1]) + "\t{:.5f}".format(coords[2]) + "\t{:.5f}".format(omega)+"\t{:.5f}".format(phi)+"\t{:.5f}".format(kappa)+"\n")
#yaw, pitch, roll = PhotoScan.utils.mat2ypr(PhotoScan.utils.opk2mat(PhotoScan.Vector((omega, phi, kappa))).t())
file.close()
print("Script finished")