欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

RealSense(1)——SDK安装及helllo-world

程序员文章站 2022-07-12 17:50:22
...

1.安装SDK
从github上下载所需工具,https://github.com/IntelRealSense/librealsense/releases,开发时只需要下载Intel.RealSense.SDK.exe 安装。
RealSense(1)——SDK安装及helllo-world

SDK默认安装路径C:\Program Files (x86)\Intel RealSense SDK 2.0

2.环境配置
当进行开发时,需要自行新建项目,配置环境,编写代码。
配置环境如下:
RealSense(1)——SDK安装及helllo-world
1.包含目录中添加:
C:\Program Files (x86)\Intel RealSense SDK 2.0\include
C:\Program Files (x86)\Intel RealSense SDK 2.0\samples
2.库目录中添加:
C:\Program Files (x86)\Intel RealSense SDK 2.0\lib\x86
3.将Intel RealSense SDK 2.0\bin\x86里面的realsense2.dll文件复制到.cpp文件同一目录下。
3.快捷配置
在项目属性管理器中加入C:\Program Files (x86)\Intel RealSense SDK 2.0
目录下的intel.realsense.props文件即可。
如下图:
RealSense(1)——SDK安装及helllo-world

4.hello-world代码
查询相机到图像中心物体的距离

#include "stdafx.h"
#include <iostream>
#include "librealsense2/rs.hpp"
#pragma comment(lib, "realsense2.lib") //等同于在链接器的输入中添加附加依赖项
using namespace rs2;
using namespace std;

void main()
{
    // Create a Pipeline, which serves as a top-level API for streaming and processing frames
    pipeline p;

    // Configure and start the pipeline
    p.start();

    while (true)
    {
        // Block program until frames arrive
        frameset frames = p.wait_for_frames();

        // Try to get a frame of a depth image
        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();

        // 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 
        cout << "The camera is facing an object " << dist_to_center << " meters away \r";
    }
}
相关标签: RealSense D415