mujoco icon indicating copy to clipboard operation
mujoco copied to clipboard

About the camera intrinsics in Mujoco

Open Lucky-hqj opened this issue 3 years ago • 6 comments

I want to set the camera intrinsics in Mujoco. How can I do that? For example, these parameters like this: intrinsics = (450., 0, 320., 0, 450., 240., 0, 0, 1) Furthermore, How should I use the mjvGLCamera in python api ?

Lucky-hqj avatar Mar 08 '23 13:03 Lucky-hqj

Cameras are modifiable via XML. Does this give you enough control over intrinsics?

If not, you should be able to edit the glCamera directly by writing into the frustum. This will give you more control, but still not allow you to introduce skewed or trapezoidal images.

How much control do you need, and why?

yuvaltassa avatar Mar 08 '23 15:03 yuvaltassa

I'm sorry, I had some confusion earlier. I have a new question now. When I use camera mode "targetbody", how can I directly get the rotation matrix of the camera from mujoco? I found that using "targetbody" method, model.cam_quat returns the default value, rather than the actual orientation.

Lucky-hqj avatar Mar 09 '23 07:03 Lucky-hqj

model.cam_quat returns the default value, rather than the actual orientation.

Information found in the model should be set only once: when a model is loaded. So this makes perfect sense.

In targetbody mode the camera orientation does change depending on the current timestep. You do have data.cam_xmat available to track this change, which should provide you the current orientation in cartesian space. I do think, however, that an updated relative orientation in form of a quaternion (e.g. data.cam_quat) would be nice to consistently keep track of (trees of) relative transformations.

DavidPL1 avatar Mar 09 '23 10:03 DavidPL1

model.cam_quat returns the default value, rather than the actual orientation.

Information found in the model should be set only once: when a model is loaded. So this makes perfect sense.

In targetbody mode the camera orientation does change depending on the current timestep. You do have data.cam_xmat available to track this change, which should provide you the current orientation in cartesian space. I do think, however, that an updated relative orientation in form of a quaternion (e.g. data.cam_quat) would be nice to consistently keep track of (trees of) relative transformations.

I am confused about the data.cam_xmat function, which seems to be inconsistent with the value I calculated. When using it to reconstruct the point cloud, I always fail to get the correct result.

Lucky-hqj avatar Mar 09 '23 17:03 Lucky-hqj

I have currently no time to double check the values of data.cam_xmat.

Does your point cloud projection work with the initial state (without moving forward in time) when you use model.cam_quat? If not, keep in mind that the actual camera orientations are rotated relative to their body frame (quoting the documentation):

The camera is looking along the -Z axis of its frame. The +X axis points to the right, and the +Y axis points up.

DavidPL1 avatar Mar 10 '23 19:03 DavidPL1

@DavidPL1's comments are all correct, thanks David!

I would also add that in MuJoCo, rotation matrices are such that the unit vectors lie on the columns. In other words, consider the x-y-z (red-green-blue) frame visualization cylinders that you can see in simulate, the vectors corresponding to these cylinders, in the world frame, would be x = {xmat[0], xmat[3], xmat[6]} etc.

yuvaltassa avatar Mar 12 '23 14:03 yuvaltassa