## How to map from 3D coordinates to 2D coordinates in image

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

### How to map from 3D coordinates to 2D coordinates in image

Hi there,

After I get the 3D coordinates of the object in the vision sensor frame, I want to extract their corresponding 2D coordinates in the output image.

I try to use some codes like

Code: Select all

cam_intrinsics = np.hstack((self.cam_intrinsics, np.zeros((self.cam_intrinsics.shape[0], 1), dtype=self.cam_intrinsics.dtype)))
p = np.matmul(cam_intrinsics, camera_vertices)
p[0] = p[0] / (p[2])
p[1] = p[1] / (p[2])
p[0] and p[1] would be the output 2D coordinates (X/Y)

However, there remains an offset from the ground truth to my calculations, I'm not sure what is wrong with my thoughts.

I also found something similar to my question, however, I did not understand the answer completely.
viewtopic.php?t=5435
coppelia wrote:
11 May 2016, 16:27
If you need to x/y position of the target object in the vision sensor's reference frame, then simply do:

Code: Select all

transformMatrix = simGetObjectMatrix(shapeObj, frontSen)
xRel=transformMatrix[4]
yRel=transformMatrix[8]
zRel=transformMatrix[12]
The reference frame of a vision sensor has Y pointing up, x pointing left, and z pointing in the viewing direction.

Cheers

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

### Re: How to map from 3D coordinates to 2D coordinates in image

I finally solve the problem. It was my mistake. Previously, I set up camera's intrinsics matrix but did not update the vision sensor.