Advertisement

realsense SDK 开发手册sample源码翻译1

阅读量:

链接:https://dev.intelrealsense.com/docs/rs-hello-realsense
例1.rs-hello-realsense
演示连接到RealSense设备和使用深度数据的基础知识

复制代码
 //**概览**:Hello RealSense示例演示了连接到RealSense设备的基础知识,并print(屏幕上输出)视野中心到物体距离的深度数据。

    
 //**Expected Output**:假设相机已连接,您应该看到“相机正对着X米外的物体”不断更新。 X是相机视野中心对象的距离(以米为单位)。
    
 //**Code Overview**:首先,include英特尔®实感™跨平台API。除了高级功能外,所有功能都通过单个标头提供:
    
  
    
 #include <iostream>
    
  
    
 #include <librealsense2/rs.hpp>
    
  
    
 using namespace rs2;
    
  
    
 void main()
    
 {
    
     // Create a Pipeline, which serves as a top-level API for streaming and processing frames
    
 	//接下来,我们创建并启动RealSense Pipeline。 Pipeline是控制摄像机枚举和流的主要高级原语。
    
     pipeline p;
    
  
    
     // Configure and start the pipeline
    
     p.start();
    
  
    
     while (true)
    
     {
    
     // Block program until frames arrive
    
 		//一旦配置了Pipeline,我们就可以循环等待新的帧。RealSense相机通常提供多个视频,
    
 		//动作或姿势流。 wait_for_frames函数将block,直到各种配置流的下一组相干帧到来。
    
     frameset frames = p.wait_for_frames();
    
  
    
     // Try to get a frame of a depth image
    
 		//从深度数据流中获取第一帧,可以使用get_depth_frame辅助函数:
    
     depth_frame depth = frames.get_depth_frame();
    
     // The frameset might not contain a depth frame, if so continue until it does
    
     if (!depth) continue;
    
  
    
     // Get the depth frame's dimensions
    
 		//接下来,我们查询默认的深度框架尺寸(这些尺寸可能因传感器而异):
    
     float width = depth.get_width();
    
     float height = depth.get_height();
    
   38.         // 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);
    
   42.         // Print the distance 
    
 		//将结果距离print到屏幕:
    
     std::cout << "The camera is facing an object " << dist_to_center << " meters away \r";
    
     }
    
 }
    
    
    
    

全部评论 (0)

还没有任何评论哟~