需求:获取物体的姿势信息(其实这里获取的是位置信息)
#include<librealsense2/rs.hpp>
#include<iostream>
#include<iomanip>
int main(int argc, char * argv[]) try
{
//声明RealSense管道,封装实际的设备和传感器
rs2::pipeline pipe;
//创建用于配置文件
rs2::config cfg;
//添加pose流
cfg.enable_stream(RS2_STREAM_POSE, RS2_FORMAT_6DOF);
//使用所选择的配置启动管道
pipe.start(cfg);
//主循环
while (true)
{
//等待相机的下一组画面
auto frams = pipe.wait_for_frames();
//从姿势流中获取帧
auto f = frams.first_or_default(RS2_STREAM_POSE);
//将框架投射到pose_frame并获取帧数据
auto pose_data = f.as<rs2::pose_frame>().get_pose_data();
//输出相对于初始位置平移的x,y,z的值
std::cout << "\r" << "Device Position: " << std::setprecision(3) << std::fixed << pose_data.translation.x << " "
<< pose_data.translation.y << " " << pose_data.translation.z << std::endl;
}
return EXIT_SUCCESS;
}
catch (const rs2::error & e)
{
}
catch (const std::exception& e)
{
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}