## How to get the coordinates in the camera frame?

Typically: "How do I... ", "How can I... " questions
Uio96
Posts: 15
Joined: 09 May 2019, 20:08

### How to get the coordinates in the camera frame?

Hi there, I'm trying to transform the coordinates from a local frame to the camera frame. It's a simple task and I just followed steps in like http://www.cs.cmu.edu/~16385/s17/Slides ... matrix.pdf like $$X_c = R(X_l - C)$$

$$X_c$$ represents coordinates in the camera frame, $$R$$ represents rotation matrix from local frame to camera frame, $$X_l$$ represents coordinates in the local frame, $$C$$ represents the center of the camera in the local frame.

It is very easy to write codes like

Code: Select all

_,camera_position=vrep.simxGetObjectPosition(self.sim_client,self.cam_handle,object_handle,vrep.simx_opmode_blocking)
_,camera_orientation=vrep.simxGetObjectOrientation(self.sim_client,self.cam_handle,object_handle,vrep.simx_opmode_blocking)

trans_object2camera_full = np.eye(4, dtype=float)
trans_object2camera_full[0:3, 3] = -camera_position[0], -camera_position[1], -camera_position[2]
rotate_object2camera_full = np.eye(4, dtype=float)
rotate_object2camera_full[0:3, 0:3] = R.from_euler('XYZ', camera_orientation).as_dcm()
transform_object2camera = np.matmul(rotate_object2camera_full, trans_object2camera_full)
camera_vertices = np.matmul(transform_object2camera, local_vertices)

However, when I try to check the calculated coordinates of the center of the local frame in the camera frame, it does not match with the ground truth by using

Code: Select all

_, camera_vertices_truth = vrep.simxGetObjectPosition(self.sim_client, object_handle, self.cam_handle, vrep.simx_opmode_blocking)
I am still very confused. Could you give me some advice? Thanks a lot.

Uio96
Posts: 15
Joined: 09 May 2019, 20:08

### Re: How to get the coordinates in the camera frame?

Hi there, I think I find another way to deal with it. Just use simGetObjectMatrix api to get the transformation matrix. I guess the previous problem is that I was not sure how to calculate the transformation matrix using pos and euler information. The exact relationship in vrep still remains ambiguous to me.

I think this post may have somthing to do this my problem. But I guess there are some typos in the given matrix viewtopic.php?t=975

coppelia
Posts: 7441
Joined: 14 Dec 2012, 00:25

### Re: How to get the coordinates in the camera frame?

Hello,

you can set/get positions/EulerAngles/Matrices in an absolute fashion, but also in a relative fashion (i.e. relative to another object), via following API functions:
The second argument of above functions is what allows you to specify relative to what you want the information.

For other matrix operations, have a look here

Cheers