Items with no label

D435 Distance

NeuroGalaxy
Beginner
3,292 Views

I am using Realsense D435 with pyrealsense2 library. Programming in python and also using OpenCV, numpy libraries.

 

I rewrote the program in python for measuring distance. Link to source: https://github.com/IntelRealSense/librealsense#ready-to-hack

 

Code:

#Camera set up   while True: frames = pipeline.wait_for_frames() depth_frame = frames.get_depth_frame() if not depth_frame: continue width = depth_frame.get_width() height = depth_frame.get_height() #print(width,height) #Calculate distance dist_to_center = depth_frame.get_distance(int(width/2), int(height/2)) print('The camera is facing an object:',dist_to_center,'meters away')

it output the distance as expected. I hold a book in the center of the camera and it calculate that distance. see picture below

 

Result: Picture1.png

However, when i moved the book below, the distance is no longer calculated.

 

Result:

Picture2.png

Currently it display distance to object at the center. I want the distance covering the whole image. how can i do this?

 

current:

Picture3.png

calculates distance at this region (yellow box on the image above)

 

I want this:Picture4.png

I want the distance for whole image (if that make sense). If an object is closer to camera at right,left,above,below or center, I want to calculate distance to that.

0 Kudos
1 Solution
Eliza_D_Intel
Employee
2,465 Views
Hello NeuroGalaxy, Thank you for your interest in the Intel RealSense D435 camera. In the line: dist_to_center = depth_frame.get_distance(int(width/2), int(height/2)) you are reading the distance only from the center of the stream, not from any other point. Therefore, the distance is calculated only from that point. If you want to get the distance from any point, you might want to check the OpenCV DNN example -https://github.com/IntelRealSense/librealsense/tree/master/wrappers/opencv/dnn which classifies and object using the RGB stream and then uses the depth stream to calculate how far is that object from the camera. Thank you and best regards, Eliza

View solution in original post

0 Kudos
5 Replies
Eliza_D_Intel
Employee
2,466 Views
Hello NeuroGalaxy, Thank you for your interest in the Intel RealSense D435 camera. In the line: dist_to_center = depth_frame.get_distance(int(width/2), int(height/2)) you are reading the distance only from the center of the stream, not from any other point. Therefore, the distance is calculated only from that point. If you want to get the distance from any point, you might want to check the OpenCV DNN example -https://github.com/IntelRealSense/librealsense/tree/master/wrappers/opencv/dnn which classifies and object using the RGB stream and then uses the depth stream to calculate how far is that object from the camera. Thank you and best regards, Eliza
0 Kudos
NeuroGalaxy
Beginner
2,465 Views

I see.

 

Is there a way to get distance using just the depth.frame.get_distance() of the whole image stream?

0 Kudos
Eliza_D_Intel
Employee
2,465 Views
Hello NeuroGalaxy, Unfortunately, Intel RealSense SDK 2.0 does not contain such an example. Thank you and best regards, Eliza
0 Kudos
NeuroGalaxy
Beginner
2,465 Views

I understand

 

I will try other methods.

0 Kudos
KIMSUNGDEOK
Beginner
1,927 Views

Hello NeuroGalaxy, I saw your post well. I want to do the program you implemented now (I want to know the code that receives distance data in real time), could you please share the code with me?

 

From.SUNGDEOK

0 Kudos
Reply