Ask Your Question

How to get the correct X Y distance from depth camera

asked 2019-02-21 19:22:36 -0500

ytosclee gravatar image

Hi, I would like to create TF for an object detected in OpenCV using depth camera. When I look at the code from the book "ROS Robotics By Example", they use the X, Y coordinate detected in the picture and put that directly into the TF. I am confused here. The X, Y coordinate is just the pixel from the photo, why they can put it in the TF directly? Thanks!

# Find the circumcircle of the green ball and draw a blue outline around it
(self.cf_u,self.cf_v),radius = cv2.minEnclosingCircle(ball_image)
ball_center = (int(self.cf_u),int(self.cf_v))

#This function builds the Crazyflie base_link tf transform and publishes it.
def update_cf_transform(self, x, y, z):
      # send position as transform from the parent "kinect2_ir_optical_frame" to the
      # child "crazyflie/base_link" (described by crazyflie.urdf.xacro)
      self.pub_tf.sendTransform(( x, y, z), tf.transformations.quaternion_from_euler(self.r, self.p, self.y),, "crazyflie/base_link", "kinect2_ir_optical_frame")

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-02-21 20:26:44 -0500

janindu gravatar image

The question 'How to get the correct XYZ from depth camera" has been answered here.

As for the question about the detect_crazyflie code, it looks like they are publishing bogus x,y values.

edit flag offensive delete link more


Hi Janindu, thanks for your help! So I need to get the X, Y, Z from the PCL and use that to create the TF.

ytosclee gravatar image ytosclee  ( 2019-02-21 20:39:14 -0500 )edit

How are you planning on getting the XYZ values from PCL?

janindu gravatar image janindu  ( 2019-02-21 20:56:08 -0500 )edit

I am using R415 realsense camera and the realsense package can output the PCL.

ytosclee gravatar image ytosclee  ( 2019-02-21 21:25:21 -0500 )edit

Ah alright, then you should be fine.

janindu gravatar image janindu  ( 2019-02-21 21:46:23 -0500 )edit

@ytosclee Can you share your code? the xyz get from pointcloud is the real distance? I tried the fx,fy,cx and cy formula to compute the distance but the result seem wrong.

BCJ gravatar image BCJ  ( 2020-07-18 08:46:23 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-02-21 19:22:36 -0500

Seen: 757 times

Last updated: Feb 21 '19