I am trying to import a mesh generated by Reality Capture (with photogrammetry) as well as the camera positions and their orientation into open3d in python. My goal is to visualize the camera direction. Importing the mesh and camera position works well, however, the orientation is always off. I think I have a problem with the rotation matrices.
I exported a mesh as well as its cameras from Reality Capture with a -90 degree rotation around the x axis. Reality Capture has z-up coordinate system, so applying the transformation makes the output suitable for open3d (which has a y-up coordinate system).
The camera file has following parameters: x,y,alt,heading,pitch,roll
Heading, pitch and roll are rotations around z, y and x in reality capture. For the camera coordinate system, z goes down, x to the "north", and y to the "east" in reality capture.
Now, visualizing the mesh and the camera positions works like a charm.
import open3d as o3d
def read_csv(path) -> list:
# returns x,y,alt,heading,pitch,roll for every camera
...
return csv_list
mesh = o3d.io.read_triangle_mesh("test.obj")
csv_list = read_csv("test.csv")
camera_spheres = []
for camera in csv_list:
x,y,alt,heading,pitch,roll = camera
sphere = o3d.geometry.TriangleMesh.create_sphere(radius=0.2).translate([x,y,alt])
camera_spheres.append(sphere)
geometries = [mesh] + camera_spheres
o3d.visualization.draw_geometries(geometries)
However, finding calculating the correct direction vector is a problem. If I understand correctly, I need to convert the angles in degrees to radians, calculate the rotation matrix
R = Rz (heading) x Ry (pitch) x Rx (roll)
And then multiply this with the cameras default direction vector. Is this the correct approach? The direction I get are always wrong or at least not shown correctly in open3d.
Thank you for any help!