[ros-users] [Discourse.ros.org] [Computer Vision / Perception] How to project 3D data into pixel coordinate?

Mehdi Tlili ros.discourse at gmail.com
Tue Sep 12 10:56:38 UTC 2017



You don't need a library for that, just use the [pinhole camera model](https://en.wikipedia.org/wiki/Pinhole_camera_model) 
here is a small python function:
def world_to_pixel(self, point):
    x = point[0]
    y = point[1]
    z = point[2]
    px = x*self.K[0][0]/z + self.K[0][2]
    py = y*self.K[1][1]/z + self.K[1][2]
    return np.asarray([px, py])

K is the 3x3 camera matrix you get from camera_info
    self.K[0][0] = cam_info.K[0]
    self.K[0][2] = cam_info.K[2]
    self.K[1][1] = cam_info.K[4]
    self.K[1][2] = cam_info.K[5]
    self.K[2][2] = 1





---
[Visit Topic](https://discourse.ros.org/t/how-to-project-3d-data-into-pixel-coordinate/2616/2) or reply to this email to respond.




More information about the ros-users mailing list