I use ZR300 to have depth data.
I took depth data in two ways.
The first one is directly take depth stream
const uint16_t * depth_image = (const uint16_t *)dev->get_frame_data(rs::stream::depth);
Full script is
const uint16_t * depth_image = (const uint16_t *)dev->get_frame_data(rs::stream::depth);
float scale = dev->get_depth_scale();
float **data;
data = new float *[HEIGHT];
for(int dy=0; dy<depth_intrin.height; ++dy)
{
data[dy] = new float[WIDTH];
for(int dx=0; dx<depth_intrin.width; ++dx)
{
uint16_t depth_value = depth_image[dy * depth_intrin.width + dx];
float depth_in_meters = depth_value * scale;
if(depth_value == 0) continue;
data[dy][dx] = depth_in_meters;
}
}
Mat depthimage(HEIGHT, WIDTH, CV_32FC1, *data);
Mat object;
threshold(depthimage, object, 0.5, 255, THRESH_BINARY);
imshow("object", object);
waitKey(1);
The second approach is as shown in the example as
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);
But the two images do not match. Two images are shown side by side and the first one is using the first method. Why the first method does not show correct image.