Forum

Author Topic: Generate camera transformation matrix from OPK data  (Read 2418 times)

Zim240

  • Newbie
  • *
  • Posts: 8
    • View Profile
Generate camera transformation matrix from OPK data
« on: February 24, 2018, 12:20:08 AM »
I am trying to get the below script working to use either the loaded OPK information in the reference tab or load from an external file. The script should function as import cameras function.

This will allow exterior orientations to be assigned to the cameras and Photoscan image alignment will not be needed.

The exteriors needs to be assigned to a specific chunk only.

The idea is to use exterior orientations from a (Image X Y Z Omega Phi Kappa) file and assign them to a specific chunk of photos. I do not want to align the photos with Photoscan.

Your help will be greatly appreciated.

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)