RealSense R400系列深度相机的彩色和深度图像获取

关于RealSense的基础使用的博文用的库有点混杂,挺多博文都是早期maneger的那个库,对那个不是很了解,主要记录一下使用最新的函数库的基础使用。

相机型号:RealSense R435

使用函数库:librealsense2/rs.hpp

1 #include <librealsense2/rs.hpp>

命名空间:rs2

1 using namespace rs2;

首先是检查设备并打印设备信息,从context里面查找device。

1 context ctx;
2 auto devicelist = ctx.query_devices();
3 device dev = *devicelist.begin();
4 cout << "rs2_camera_name: " << dev.get_info(RS2_CAMERA_INFO_NAME) << endl;    //相机名字
5 cout << "rs2_camera_serial_number: " << dev.get_info(RS2_CAMERA_INFO_SERIAL_NUMBER) << endl;    //序列号
6 cout << "rs2_firmware_version: " << dev.get_info(RS2_CAMERA_INFO_FIRMWARE_VERSION) << endl;    //固件版本

其次是设置RGB色彩和深度视频流参数,使用config来完成,此外还可以设置使用补洞滤波hole_filling_filter hole_filter。

1 config cfg;
2 cfg.enable_stream(RS2_STREAM_DEPTH, 1280, 720, RS2_FORMAT_Z16, 30);
3 cfg.enable_stream(RS2_STREAM_COLOR, 1280, 720, RS2_FORMAT_BGR8, 30);
4 
5 hole_filling_filter hole_filter;
6 hole_filter.set_option(RS2_OPTION_HOLES_FILL, 2);

最后开启管道,并将设置的config值放入。在循环中等待帧集的到来,并从中读出depth frame 和 color frame即可。

1 pipeline pipe;
2 pipe.start(cfg);
3 
4 while(1)
5 {
6     frameset frames = pipe.wait_for_frames();
7     depth_frame depth = frames.get_depth_frame();
8     frame color = frames.get_color_frame(); 
9 }

猜你喜欢

转载自www.cnblogs.com/mushroomchan/p/get_frame_from_realsense.html
今日推荐