# Forum

### Author Topic: Camera Location and Centre Vector  (Read 3057 times)

#### photo_man

• Newbie
• Posts: 10
##### Camera Location and Centre Vector
« on: June 05, 2019, 03:57:29 PM »
Hello,

I have a chunk in a local coordinate system with scale bars.
For all enabled cameras I want to extract their X,Y,Z coordinate in the local system and a vector that goes through the centre point of the image.

If it's also possible, I would also like to get the X,Y,Z coordinate of the intersection point of the vector with the mesh.

Is this possible through python scripting?

Thanks!

• Newbie
• Posts: 33
##### Re: Camera Location and Centre Vector
« Reply #1 on: June 07, 2019, 01:44:51 PM »
Hello,

I have a chunk in a local coordinate system with scale bars.
For all enabled cameras I want to extract their X,Y,Z coordinate in the local system and a vector that goes through the centre point of the image.

If it's also possible, I would also like to get the X,Y,Z coordinate of the intersection point of the vector with the mesh.

Is this possible through python scripting?

Thanks!

Hey Photo_man, you can use the following code to retrieve points and rotation in local 3D coordinates like the following if the chunk has not been assigned with a geographic coordinates. The vector through image center is just [0,0-1]*rot(yaw)*rot(pitch)*rot(roll)
how metashape defines the rotation order and rotation matrix have to be checked on somewhere else

Code: [Select]
`label_l,  yaw_l, pitch_l, roll_l=[],[],[],[]    cameras=chunk.cameras    for camera in cameras:        T = chunk.transform.matrix        m = chunk.crs.localframe(T.mulp(camera.center))        R = m * T * camera.transform * Metashape.Matrix().Diag([1, -1, -1, 1])        row = list()            for j in range (0, 3): #creating normalized rotation matrix 3x3        row.append(R.row(j))        row[j].size = 3        row[j].normalize()    R = Metashape.Matrix([row[0], row[1], row[2]])    yaw,pitch,roll = Metashape.utils.mat2ypr(R)      yaw_l.append(yaw)    pitch_l.append(pitch)    roll_l.append(roll)    label_l.append(camera.label)        table= pd.DataFrame(data={'Label':label_l,'Yaw':yaw_l,'Pitch':pitch_l,'Roll':roll_l},                          columns=['Label','Yaw','Pitch','Roll'])        table.to_csv(pose_file)      `

#### photo_man

• Newbie
• Posts: 10
##### Re: Camera Location and Centre Vector
« Reply #2 on: June 18, 2019, 06:04:55 PM »
`import PhotoScan #Photoscan 1.4.1file1 = open(path, "wt")chunk = PhotoScan.app.document.chunk #active chunkcameras=chunk.camerasfor camera in cameras: # Loop through cameras    if camera.enabled is True: # Only apply to enabled cameras        estimated_coord = chunk.crs.project(chunk.transform.matrix.mulp(camera.center)) #estimated XYZ in coordinate system units        cam_vec_int = camera.transform.mulv(PhotoScan.Vector([0,0,1]))        cam_vec_ext = chunk.transform.matrix.mulv(cam_vec_int)        cam_vec_ext.normalize()        print(camera.label, estimated_coord, cam_vec_ext) file1.write(camera.label + "," + "{:.8f}".format(estimated_coord) + "," + "{:.8f}".format(cam_vec_ext) + "\n")  #writing camerasfile1.write("#\n")file1.close()`