当前位置: 代码迷 >> 综合 >> Ubuntu16.04+Intel realsense D435+Qt
  详细解决方案

Ubuntu16.04+Intel realsense D435+Qt

热度:56   发布时间:2024-02-26 15:09:28.0

ubuntu16.04 + Intel realsense D435 + Qt

    • D435_SDK安装
      • 版本支持
      • 下载、解压
      • 编译前的准备工作
      • 编译、安装
      • 安装后续工作
    • D435_Qt
    • 参考

D435_SDK安装

版本支持

平台支持、设备支持、Firmware支持、语言支持等,参阅这里。

下载、解压

下载并解压SDK,这里选择v2.39.0(原因参阅第一条链接)。

编译前的准备工作

1)查看linux内核,要求版本 >=4.4.0-50

$ uname -r

2)查看cmake版本,要求版本 >3.6

$ cmake --version

3)安装必要依赖

$ sudo apt-get install libusb-1.0-0-dev pkg-config libgtk-3-dev libssl-dev

编译、安装

$ sudo librealsense-2.39.0
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

安装后续工作

1)断开D435的连接,安装ideo4Linux视频内核驱动

$ sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules && udevadm trigger

2)编译配置文件

$ librealsense-2.39.0/scripts/patch-realsense-ubuntu-lts.sh

3)接上D435,打开realsense-viewer,连接成功会有图像,没有图像检查USB是否为3.0等问题

$ realsense-viewer

D435_Qt

1、添加库,使用Qt添加安装的库_/usr/local/lib/librealsense2.so,使用默认头文件路径

2、使用D435,参考github提供的例程,以hello-realsense为例

1)包含头文件,注意是rs.hpp,不是rs.h,hpp文件带有函数实现

#include <librealsense2/rs.hpp>
#include <iostream>

2)添加个按钮

void MainWindow::on_pushButton_clicked()
{
    // Create a Pipeline - this serves as a top-level API for streaming and processing framesrs2::pipeline p;// Configure and start the pipelinep.start();int cnt=10;while (cnt>0){
    // Block program until frames arrivers2::frameset frames = p.wait_for_frames();// Try to get a frame of a depth imagers2::depth_frame depth = frames.get_depth_frame();// Get the depth frame's dimensionsfloat width = depth.get_width();float height = depth.get_height();// Query the distance from the camera to the object in the center of the imagefloat dist_to_center = depth.get_distance(width / 2, height / 2);// Print the distanceqDebug()<<"The camera is facing an object "+QString::number(dist_to_center)+" meters away \r";cnt--;}
}

输出如下:

"The camera is facing an object 2.527 meters away \r"
"The camera is facing an object 2.527 meters away \r"
"The camera is facing an object 2.556 meters away \r"
"The camera is facing an object 2.546 meters away \r"
"The camera is facing an object 2.527 meters away \r"
"The camera is facing an object 2.556 meters away \r"
"The camera is facing an object 2.546 meters away \r"
"The camera is facing an object 2.556 meters away \r"
"The camera is facing an object 2.556 meters away \r"
"The camera is facing an object 2.585 meters away \r"

参考

1)Ubuntu 16.04 安装RealSense D435教程
2)https://github.com/IntelRealSense/librealsense
3)https://www.intelrealsense.com/

  相关解决方案