Hi again,
if you want to write a pandas Df with ImageId, Estimated position (3) and estimated rotation (3), i.e. 7 colums following code would do the trick:
import numpy as np
import pandas as pd
def getAntennaTransform(sensor):
location = sensor.antenna.location
if location is None:
location = sensor.antenna.location_ref
rotation = sensor.antenna.rotation
if rotation is None:
rotation = sensor.antenna.rotation_ref
return Metashape.Matrix.Diag((1, -1, -1, 1)) * Metashape.Matrix.Translation(location) * Metashape.Matrix.Rotation(Metashape.Utils.ypr2mat(rotation))
def getcolumnsName(euler_angles):
if euler_angles == Metashape.EulerAnglesOPK:
return ['Id','X_Est','Y_Est','Z_Est','Omega_Est','Phi_Est','Kappa_Est']
if euler_angles == Metashape.EulerAnglesPOK:
return ['Id','X_Est','Y_Est','Z_Est','Phi_Est','Omega_Est','Kappa_Est']
if euler_angles == Metashape.EulerAnglesYPR:
return ['Id','X_Est','Y_Est','Z_Est','Yaw_Est','Pitch_Est','Roll_Est']
if euler_angles == Metashape.EulerAnglesANK:
return ['Id','X_Est','Y_Est','Z_Est','Alpha_Est','Nu_Est','Kappa_Est']
chunk = Metashape.app.document.chunk
est = list()
for camera in chunk.cameras:
if not camera.transform:
continue
transform = chunk.transform.matrix
crs = chunk.crs
if chunk.camera_crs:
transform = Metashape.CoordinateSystem.datumTransform(crs, chunk.camera_crs) * transform
crs = chunk.camera_crs
ecef_crs = crs.geoccs
camera_transform = transform * camera.transform
antenna_transform = getAntennaTransform(camera.sensor)
location_ecef = camera_transform.translation() + camera_transform.rotation() * antenna_transform.translation()
rotation_ecef = camera_transform.rotation() * antenna_transform.rotation()
est_loc = Metashape.CoordinateSystem.transform(location_ecef, ecef_crs, crs)
if chunk.euler_angles == Metashape.EulerAnglesOPK or chunk.euler_angles == Metashape.EulerAnglesPOK:
localframe = crs.localframe(location_ecef)
else:
localframe = ecef_crs.localframe(location_ecef)
est_rot = Metashape.utils.mat2euler(localframe.rotation() * rotation_ecef, chunk.euler_angles)
est.append([camera.label,est_loc.x,est_loc.y,est_loc.z,est_rot.x,est_rot.y,est_rot.z])
pd.DataFrame(np.array(est),columns = getcolumnsName(chunk.euler_angles))
and resut would be like the following for 3 image data set....