dfki-ric / pytransform3d

3D transformations for Python.
https://dfki-ric.github.io/pytransform3d/
Other
632 stars 68 forks source link

Confusion with the Camera Trajectory example #193

Closed Mechazo11 closed 2 years ago

Mechazo11 commented 2 years ago

Hello @AlexanderFabisch

I have two queries regarding the Camera Trajectory example found here https://dfki-ric.github.io/pytransform3d/_auto_examples/plots/plot_camera_trajectory.html#sphx-glr-auto-examples-plots-plot-camera-trajectory-py

  1. Why are we performing ax = ptr.plot_trajectory(ax, P=P, s=0.1, n_frames=10) operation when the main plotting loop for i, c in zip(key_frames_indices, colors): is using cam2world_trajectory = ptr.transforms_from_pqs(P) which converted the pose in (x,y,z,qw,qx,qy,qz) into a 4x4 SE(4) matrix? I saved my odometry data in (x,y,z,qw,qx,qy,qz) format to match with TUM dataset (if I am not mistaken how they saved their poses)

  2. My camera's coordinate frame is defined as Z, X, Y where +Z refers to translating forward, +X refers to translating right and +Y refers to translating vertically down. Is there a setting that we can change so that the generated 3D plot is oriented in this coordinate frame?

With best, Mechazo11

AlexanderFabisch commented 2 years ago

Why are we performing ax = ptr.plot_trajectory(ax, P=P, s=0.1, n_frames=10) operation when the main plotting loop for i, c in zip(key_frames_indices, colors): is using cam2world_trajectory = ptr.transforms_from_pqs(P) which converted the pose in (x,y,z,qw,qx,qy,qz) into a 4x4 SE(4) matrix? I saved my odometry data in (x,y,z,qw,qx,qy,qz) format to match with TUM dataset (if I am not mistaken how they saved their poses)

I don't see a problem here? Using a transformation matrix at the interface of plot_camera is more convenient since most of the time I saw extrinsic camera parameters represented by a transformation matrix. A more convenient format to store pose trajectories is the position + quaternion format. pytransform3d offers a function to convert between the two formats, so everything should be fine.

My camera's coordinate frame is defined as Z, X, Y where +Z refers to translating forward, +X refers to translating right and +Y refers to translating vertically down. Is there a setting that we can change so that the generated 3D plot is oriented in this coordinate frame?

This is exactly how the coordinate frame is defined here. See here.

Mechazo11 commented 2 years ago

@AlexanderFabisch , Regarding the 2nd comment, can we pass an argument that would flip positions of Y and Z in https://dfki-ric.github.io/pytransform3d/_auto_examples/plots/plot_camera_3d.html#sphx-glr-auto-examples-plots-plot-camera-3d-py ?

AlexanderFabisch commented 2 years ago

I am not yet convinced that it is actually a useful contribution and not just a weird special case. Could you give me some links to documents that use this convention (and maybe describe it in detail)?

Mechazo11 commented 2 years ago

@AlexanderFabisch I found this StackExchange post which shows what I am trying to achieve in terms of visualization.

https://stackoverflow.com/questions/8178467/how-to-plot-the-camera-and-image-positions-from-camera-calibration-data

AlexanderFabisch commented 2 years ago

But again, y is downward, x to the right. I don't see the difference?

Mechazo11 commented 2 years ago

@AlexanderFabisch, I think the pytransform3d methods that perform the conversion from transformation matrices to position,quaternion are indeed orienting the axes correctly. But the plotting tools are putting Z axis on the vertical which is making any forward translation of the robot show up as a change in height of the graph. Hence, I was looking for a way to swap the axes so that forward translation of the robot would cause a change in length of the graph. Anyways, I am making a 2d graph for the time being to visualize the output for the time being. Thanks for replying to my queries.

AlexanderFabisch commented 2 years ago

But the plotting tools are putting Z axis on the vertical which is making any forward translation of the robot show up as a change in height of the graph. Hence, I was looking for a way to swap the axes so that forward translation of the robot would cause a change in length of the graph. Anyways, I am making a 2d graph for the time being to visualize the output for the time being. Thanks for replying to my queries.

I think you are confusing position and orientation. The position along the z component indeed translates the camera frame along the z-axis of the world frame. The z-axis in the orientation still points forward along one of the horizontal world axes.