Items with no label
3335 Discussions

D435 Measuring Dist on RGB in Realtime [Python]

NeuroGalaxy
Beginner
3,230 Views

I tried many different distance calculation using this realsense D435 camera. I program mainly in python and mostly uses RGB input rather than depth. I want to calculate distance between the camera to an nearest object. If possible to calculate the distance in depth or RGB, please advice.

0 Kudos
6 Replies
MartyG
Honored Contributor III
2,444 Views

Intel has created a tutorial in Python for measuring distance that is called distance_to_object.

 

https://github.com/IntelRealSense/librealsense/blob/jupyter/notebooks/distance_to_object.ipynb

NeuroGalaxy
Beginner
2,444 Views

I tried this method before. However it uses trained information of the dog and other classes, a deep learning based detection, then draw distance to the detected box.

Is it possible to get distance, based on objects very close to the camera? (without using deep learning to detect objects, assuming detection is based on an object close to camera or not? )

0 Kudos
MartyG
Honored Contributor III
2,444 Views

A possible solution is offered in the link below. In the second comment, a user looked at the C++ code for measuring depth and adapted it for Python.

 

https://stackoverflow.com/questions/52677479/exact-depth-distance-from-realsense-f435-with-x-y-coordinates

 

**************

 

pipeline = rs.pipeline()

config = rs.config()

profile = pipeline.start(config)

frames = pipeline.wait_for_frames()

  while True:

    depth_frame = frames.get_depth_frame()

    zDepth = depth_frame.get_distance(int(x),int(y))

NeuroGalaxy
Beginner
2,444 Views

Thank you. I tried using this method and seems to be working. I created a colour detection program and drawn bounding boxes around them and calculated the midpoints. I then added those midpoints to the depth image, which prints distance in cm.

 

I measured it in real world using a measurement tape, it seems more or less correct but the distance sometimes goes over or below by few cm. I am using resolution 640 x 360 for colour and depth image. Is this happening because the depth error increases if the resolution gets lower?

0 Kudos
MartyG
Honored Contributor III
2,444 Views

The 400 Series cameras have something called 'RMS Error'. What this means is that as the distance of an object from the camera increases, the RMS Error (depth noise) increases, causing the accuracy of the depth readings to drift. At close range, this drift is small. After around 3 meters distance and beyond, the error starts to increase noticably. The D435's error-over-distance is significantly more than the D415 model due to the D435's hardware design.

 

The error over distance can be observed on the chart below. The D435 is the upper of the two curves. Left-click on the image to view it in full size.

 

1.png

 

You can view the Intel camera tuning guide the chart was taken from at this link:

 

https://realsense.intel.com/wp-content/uploads/sites/63/BKM-For-Tuning-D435-and-D415-Cameras-Webinar_Rev3.pdf?language=en_US

NeuroGalaxy
Beginner
2,444 Views

This information is useful. Thank you.

 

 

0 Kudos
Reply