hello realsense
头文件
#include <librealsense2/rs.hpp> // Include Intel RealSense Cross Platform API
创建并启动通道
// Create a Pipeline - this serves as a top-level API for streaming and processing frames
rs2::pipeline p;
// Configure and start the pipeline
p.start();
一旦管道配置,我们可以循环等待新帧。英特尔RealSense摄像头通常提供多种视频、动作或姿势流。函数将阻塞,直到来自不同配置流的下一组一致帧。
wait_for_frames
// Block program until frames arrive
rs2::frameset frames = p.wait_for_frames();
要从深度数据流中获取第一帧,可以使用helper函数:
get_depth_frame
// Try to get a frame of a depth image
rs2::depth_frame depth = frames.get_depth_frame();
查询默认的深度帧尺寸(这些可能因传感器而异):
// Get the depth frame's dimensions
float width = depth.get_width();
float height = depth.get_height();
要获得特定像素(帧的中心)的距离,可以使用函数:get distance
// Query the distance from the camera to the object in the center of the image
float dist_to_center = depth.get_distance(width / 2, height / 2);
打印距离
// Print the distance
std::cout << "The camera is facing an object " << dist_to_center << " meters away \r";