-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_depth.cpp
31 lines (25 loc) · 1004 Bytes
/
read_depth.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <librealsense2/rs.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(){
rs2::pipeline pipe;
pipe.start();
cv::namedWindow("Display Image", cv::WINDOW_AUTOSIZE );
while (1)
{
rs2::frameset frames = pipe.wait_for_frames();
rs2::depth_frame depth = frames.get_depth_frame();
// CAPTURE A FRAME
// Query frame size (width and height)
const int width = depth.as<rs2::video_frame>().get_width();
const int height = depth.as<rs2::video_frame>().get_height();
// Create OpenCV matrix of size (w,h) from the colorized depth data
cv::Mat depth_img(cv::Size(width, height), CV_16UC1, (void*)depth.get_data(), cv::Mat::AUTO_STEP);
// Convert 16bit image to 8bit image
depth_img.convertTo(color_img, CV_8UC1, 15 / 256.0);
cv::imshow("Display Image", depth_img);
cv::waitKey(3);
}
return 0;
}