Get xyz of a pixel in a depth image

asked 2023-04-03 16:06:41 -0500

maxconway gravatar image

Hi everyone. I have a rep118 depth image, and a stream of pixel coordinates. given pixel coordinates u,v I want to find the xyz position of the pixel (u,v) from the depth image and place a marker there. I am struggling to get the coordinates out of the depth image. So far I have

            points = []
            for u, v in coords:
                if u < 0 or v < 0 or u >= self.depth_image.shape[1] or v >= self.depth_image.shape[0]:
                    rospy.logerr("Invalid pixel coordinates")
                    depths.append(0.0)
                else:
                   depth_value = self.depth_image[v, u]
                    x = f(u,v, depth_value, camera_info)
                    y = g(u,v, depth_value, camera_info)
                    z = h(depth_value, camera_info)
                    points.append([x, y, z])

How would you insert code for f(u,v, depth_value, camera_info), g(u,v, depth_value, camera_info), h(depth_value, camera_info) to properly calculate the position of a point. Importantly I do not want to convert the entire depth image into a pointcloud because I will only have 10-20 points I need the position of.

edit retag flag offensive close merge delete