Items with no label
3341 Diskussionen

Retrieving depth information from ZR300

nnain1
Neuer Beitragender I
3.782Aufrufe

I used ZR300 for depth measurement.

I can't retrieve correct Depth matrix from the camera.

What I did was as follow and retrieve the depth matrix from the stream.

const uint16_t * depth_image = (const uint16_t *)dev->get_frame_data(rs::stream::depth);

float scale = dev->get_depth_scale();

float data[HEIGHT*WIDTH];

for(int dy=0; dy

{

for(int dx=0; dx

{

uint16_t depth_value = depth_image[dy * depth_intrin.width + dx];

if(depth_value == 0)

continue;

else

data[dy*dx] = (float)depth_value * scale;

}

}

Mat depthimage(HEIGHT, WIDTH, CV_32FC1, &data);

Mat colorimage(HEIGHT, WIDTH, CV_8UC3, (uchar*)dev->get_frame_data(rs::stream::color));

imshow("dst", depthimage);

waitKey(1);

dst.release();

I have another depth follow sample from realsense, that has correct object.

The code is

glPixelTransferf(GL_RED_SCALE, 0xFFFF * dev->get_depth_scale() / 2.8f);

glDrawPixels(WIDTH, HEIGHT, GL_RED, GL_UNSIGNED_SHORT, dev->get_frame_data(rs::stream::depth));

glPixelTransferf(GL_RED_SCALE, 1.0f);

Red color image is the one following sample program and the image "dst" is the one using the first code.

Another one is the color image, we can see there is a cabinet.

Why I don't have correct depth image, what is wrong with my code?

0 Kudos
6 Antworten
idata
Mitarbeiter
2.456Aufrufe

Hello inmn,

 

Sorry for the late response. While we don't usually debug customer's code, I am trying to reproduce your issue but have encountered some obstacles. Please stay tuned...

 

 

Regards,

 

Jesus

 

Intel Customer Support

 

idata
Mitarbeiter
2.456Aufrufe

Hello inmn,

 

 

It seems that you have to do a conversion of the pixel formats from RealSense to OpenCV. See the file https://github.com/IntelRealSense/realsense_sdk_zr300/blob/master/sdk/src/core/image/image_conversion_util.cpp for an example of how to do this.

 

 

Let us know if this helps.

 

 

Regards,

 

Jesus

 

Intel Customer Support
nnain1
Neuer Beitragender I
2.456Aufrufe

Hello Jesus,

Many thanks for the reply.

I have the same issue for color image. I tried to grab into Opencv's Mat image.

What I did was

dev.enable_stream(rs::stream::color, 640, 480, rs::format::bgr8, 60); cv::Mat colorImg(480, 640, CV_8UC3, (unsigned char *)dev.get_frame_data(rs::stream::color)); imshow("colorImg",colorImg); cv::waitKey(1);

Then my color image became. Is that the same issue as I need to pixel format conversion?

nnain1
Neuer Beitragender I
2.456Aufrufe

Can I have any sample of usage?

nnain1
Neuer Beitragender I
2.456Aufrufe

Thanks now ok.

I take the image as rgb8

dev.enable_stream(rs::stream::color, 640, 480, rs::format::rgb8, 60);

Then convert to RGBtoBGR

cv::cvtColor(srcMat, grayMat, CV_RGB2BGR);

It works.

nnain1
Neuer Beitragender I
2.456Aufrufe

Hello Jesus,

Many thanks for the reply.

I have the same issue for color image. I tried to grab into Opencv's Mat image.

What I did was

dev.enable_stream(rs::stream::color, 640, 480, rs::format::bgr8, 60); cv::Mat colorImg(480, 640, CV_8UC3, (unsigned char *)dev.get_frame_data(rs::stream::color)); imshow("colorImg",colorImg); cv::waitKey(1);

Then my color image became. Is that the same issue as I need to pixel format conversion?

Antworten