Ubuntu 16.04 中 Kinect 2.0 的 libfreenect2 驱动配置及其图像读取编程实现

在之前的几篇文章中,说明了如何在Ubuntu 16.04中配置OpenCV 3.4.1,并根据一些OpenCV的教程完成了其基本知识内容的学习,但在学习过程中用于实验的图像大部分是来自网络或是借助于笔记本电脑的摄像头,而为了完成一些更加复杂的任务,需要使用其它的视觉传感器,所以在这里记录一下Ubuntu 16.04使用Kinect 2.0 RGB-D传感器的内容。


1. 驱动安装

Kinect 2.0 在Windows系统中是有官方提供的现成的驱动程序可以使用的,并且有对应的SDK可以辅助开发人员进行应用开发,但在Linux系统中,就需要在Github上找对应的开源驱动代码,并且进行安装调试。

Kinect 2.0 的开源驱动包位于:https://github.com/OpenKinect

在其内有两类驱动,一类是 libfreenect 用于一代Kinect的驱动,另一类 libfreenect2 用于二代Kinect的驱动,在本文中用的是二代驱动程序。以下内容是针对Ubuntu系统说明的,如果要查看其它系统,则可以移步到:https://github.com/OpenKinect/libfreenect2查看驱动包的详细说明。

1.1 硬件要求

  • USB 3.0 controller. USB 2 is not supported.

Virtual machines likely do not work, because USB 3.0 isochronous transfer is quite delicate.

1.2 操作系统要求

因为我们只关注Ubuntu所以只列出Ubuntu系统的要求:

  • Debian, Ubuntu 14.04 or newer, probably other Linux distros. Recommend kernel 3.16+ or as new as possible.

1.3 可选择的配置选项

  • OpenGL depth processing: OpenGL 3.1 (Windows, Linux, Mac OS X). OpenGL ES is not supported at the moment.
  • OpenCL depth processing: OpenCL 1.1
  • CUDA depth processing: CUDA (6.5 and 7.5 are tested; The minimum version is not clear.)
  • VAAPI JPEG decoding: Intel (minimum Ivy Bridge or newer) and Linux only
  • OpenNI2 integration: OpenNI2 2.2.0.33
  • Jetson TK1: Linux4Tegra 21.3 or later. Check Jetson TK1 issues before installation. Jetson TX1 is not yet supported as the developers don’t have one, but it may be easy to add the support.

1.4 安装Kinect 2.0驱动

  • 下载驱动包:
cd ~    #设置克隆目录,当前在Home目录中,也可以设置在其它目录中
git clone https://github.com/OpenKinect/libfreenect2.git  
cd libfreenect2
  • 安装编译工具:
sudo apt-get install build-essential cmake pkg-config
  • 安装libusb. The version must be >= 1.0.20:
sudo apt-get install libusb-1.0-0-dev
  • 安装TurboJPEG:
sudo apt-get install libturbojpeg libjpeg-turbo8-dev
  • 安装OpenGL:
sudo apt-get install libglfw3-dev
  • 安装OpenNI2:
sudo apt-get install libopenni2-dev
  • 编译构建:
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/  #修改了原来的安装位置
make
sudo make install  #这里直接用root权限安装,如果是普通权限有的时候会出现安装不成功的情况
  • 设置udev规则:
sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
  • 将Kinect重新接入,之后运行测试命令:
./bin/Protonect  #重新接入之后运行测试
sudo apt-get install openni2-utils && sudo make install-openni2 && NiViewer2 #可选测试

重新接入的过程中,如果只是重新插拨一下USB接口,可能并不会生效,最稳妥的办法是将Kinect断电之后重新上电,在上下电的过程中USB接口可以不用重新插拨。

1.5 测试结果

以上所有步骤如果不出问题,则可以得到类似以下内容:
测试图片

运行可选的测试命令也会出现类似的图像,但那个是全屏的,按下ESC就可以退出,就不再放图片了,所以到了这一步,驱动包的安装就已经成功了,下面的内容是如果在代码中使用传感器获取数据,这一步才是最需要关注的。

2. 编程实现

编程实现通过Ubuntu读取Kinect的数据,同样需要借助于驱动包所提供的库函数,下面就详细解释如何在程序中实现数据的获取与处理。首先以下为需要包含的头文件:

#include <libfreenect2/libfreenect2.hpp>
#include <libfreenect2/frame_listener_impl.h>
#include <libfreenect2/registration.h>
#include <libfreenect2/packet_pipeline.h>
#include <libfreenect2/logger.h>  #用于日志信息,视需求可省略

具体代码的实现参考了以下网址:

http://answers.opencv.org/question/76468/opencvkinect-onekinect-for-windows-v2linuxlibfreenect2/

  • 17
    点赞
  • 116
    收藏
    觉得还不错? 一键收藏
  • 18
    评论
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值