6 Replies Latest reply on Jan 31, 2018 7:33 PM by inmn

    Retrieving depth information from ZR300


      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<HEIGHT; ++dy)



                  for(int dx=0; dx<WIDTH; ++dx)


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


                       if(depth_value == 0)



                          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);



      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?


      Screenshot from 2018-01-12 09-12-39.png