librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

Save the depth map and read the depth value of specific pixel position with OpenCV

Open afenghandsome opened this issue 4 years ago • 5 comments

hello,I want to ask two questions,

  1. We use the align function to align the depth map with the color map, and then use get_ Distance() obtains the depth value from the depth map. Now save the depth map with the type of mat depth_ image(Size(depth_w,depth_h), CV_ 8UC3, (void*)depth_ frame. get_ data(), Mat::AUTO_ STEP); This picture is color. Read this picture with OpenCV. How to read the depth value of this picture.

图片

  1. I use an alignment function written by myself to align the depth map to the color map. The mat type makes 16 bit data, mat depth_ image(Size(depth_w, depth_h), CV_ 16U, (void*)depth_ frame. get_ data(), Mat::AUTO_ STEP); The image is like this. It's gray. I open this image with OpenCV. How can I get the depth value of a specific pixel. 1

afenghandsome avatar May 10 '22 02:05 afenghandsome

Hi @afenghandsome For your first question about obtaining a depth value from an OpenCV mat, I hope that the script references in the links below will be helpful.

https://github.com/IntelRealSense/librealsense/issues/6239#issuecomment-615249398

https://support.intelrealsense.com/hc/en-us/community/posts/4402828074899-intel-realsense-object-center-pixel-to-coordinate-coverstion

In the second question, if you are using CV_16U in that image then the code suggested by a RealSense team member at https://github.com/IntelRealSense/librealsense/issues/2231#issuecomment-412804368 may help you to obtain the depth value from the aligned mat image.

MartyG-RealSense avatar May 10 '22 05:05 MartyG-RealSense

@MartyG-RealSense Thank you for your reply. I use opencv's imwrite to save the picture to my computer, and then create a new project to load my picture, so I can't use get without turning on the camera_ Distance() function to get the depth value.

Now my idea is to use the method in OpenCV to obtain the depth value from these two images respectively. Do you have any good suggestions?

afenghandsome avatar May 10 '22 08:05 afenghandsome

A problem with trying to obtain depth values from PNG images (if that is the file format that you saved to) is that most of the depth information is lost during export, making it very hard to get a usefully accurate depth value from a PNG.

MartyG-RealSense avatar May 10 '22 15:05 MartyG-RealSense

Hi @afenghandsome Do you require further assistance with this case, please? Thanks!

MartyG-RealSense avatar May 16 '22 05:05 MartyG-RealSense

Case closed due to no further comments received.

MartyG-RealSense avatar May 22 '22 07:05 MartyG-RealSense