intel realsense SDK学习

该代码示例展示了如何使用librealsense2库创建一个管道来启动英特尔RealSense摄像头的流,并获取深度帧。程序会阻塞直到接收到新帧,然后从深度帧中提取中心点的像素距离,计算出物体与相机之间的距离。
摘要由CSDN通过智能技术生成

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值