ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to get the distance and the angle (distance and bearing) from a depth camera

asked 2018-08-15 08:21:00 -0600

Jad gravatar image

Hi,

I am using deep learning to detect an object and after I got the detection work, I made boxes around this object and I calculated the mid point of the box. Now I want to measure the distance and the angle between the camera and the mid point of the box around the object. I manged to get the coordinates of the mid point x,y in a frame but still don't know to calculate the distance and bearing. Thanks for advance. ps: I am using realsense camera D435.

Jad

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
0

answered 2018-08-15 14:04:31 -0600

You should be able to find this information with a tangent function. With the pose of the camera and pose of the box in some global, identical frame (could even be camera frame) you can use the change in Y and change in X to pull out the azimuth angle if you're looking for 2D. You can use the change in Z as well to pull out azimuth and elevation angles.

It sounds like you already have distance, so that's a good start!

edit flag offensive delete link more

Comments

Thanks ! . Yes I got the distance so now I can measure the distance but need to figure out how to get the angle. I will try to apply what you have said. :)

Jad gravatar image Jad  ( 2018-08-16 05:59:29 -0600 )edit
1

Awesome, can you mark the answer as correct then to close it out for maintainers?

stevemacenski gravatar image stevemacenski  ( 2018-08-16 18:20:15 -0600 )edit

@Jad, hi, would you please share your code with me as wwll? i have the same problem, get the distance and bearing of the nearest object

Delbina gravatar image Delbina  ( 2022-08-05 08:50:39 -0600 )edit
0

answered 2018-08-15 15:41:51 -0600

zubair gravatar image

you can actually find the distance using point cloud 2 library, together with the topic /depth_registered_points. its working smooth.

edit flag offensive delete link more

Comments

you can use this :

int arrayPosition = y * my_pcl.row_step + x * my_pcl.point_step;
        int arrayPosZ = arrayPosition + my_pcl.fields[3].offset;

to get the depth, and then use :

memcpy(&Z_pos, &my_pcl.data[arrayPosZ], sizeof(float));

to get them

zubair gravatar image zubair  ( 2018-08-15 15:44:11 -0600 )edit

Thank you !! I manged to get the distance but now need to get the angle because i will use those landmarks for feature-based SLAM.

Jad gravatar image Jad  ( 2018-08-16 06:03:35 -0600 )edit
0

answered 2018-08-15 08:57:36 -0600

pavel92 gravatar image

Are you using the realsense2_camera package?
You should be able to access the depth value of the pixel from the depth image that you get with the camera. It should be published on a topic like depth/image_raw (sensor_msgs/Image) and it should contain uint16 depth values in mm. About the angle, I am not sure if there is a simpler way but based on the depth value that you get you can calculate the angle using simple trigonometry.

edit flag offensive delete link more

Comments

Thanks. Yes I am using this library and I manged to get the distance but I was wondering if there is already a simple solution for the angle.

Jad gravatar image Jad  ( 2018-08-16 05:55:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-08-15 08:21:00 -0600

Seen: 3,924 times

Last updated: Aug 15 '18