ROS与深度相机入门教程-在ROS使用kinect v2摄像头
说明
- 介绍如何在ros中安装和使用kinect v2摄像头
- 介绍libfreenect2包使用,kinect v2的开源驱动
- 介绍iai_kinect2包,kinect v2的ros包
- 测试环境:Ubuntu 14.04/16.04 + ROS indigo/kinetic
libfreenect2安装
- 默认已经安装opencv
- 安装其他依赖:
$ sudo apt-get install build-essential cmake pkg-config libturbojpeg libjpeg-turbo8-dev mesa-common-dev freeglut3-dev libxrandr-dev libxi-dev
- 下载libfreenect2驱动:
$ cd ~
$ git clone https://github.com/OpenKinect/libfreenect2.git
$ cd libfreenect2
$ cd depends; ./download_debs_trusty.sh
- 安装libusb
$ sudo dpkg -i debs/libusb*deb
- 安装 TurboJPEG
$ sudo apt-get install libturbojpeg libjpeg-turbo8-dev
- 安装GLFW3
$ sudo apt-get install libglfw3-dev
- 如果上面安装不了,使用如下方法:
$ cd libfreenect2/depends
$ sh install_ubuntu.sh
$ sudo dpkg -i libglfw3*_3.0.4-1_*.deb
- 安装OpenGL的支持库
$ sudo dpkg -i debs/libglfw3*deb; sudo apt-get install -f; sudo apt-get install libgl1-mesa-dri-lts-vivid
- 如果最后的命令有冲突,忽略就行
- 安装OpenCL的支持库
$ sudo apt-add-repository ppa:floe/beignet; sudo apt-get update; sudo apt-get install beignet-dev; sudo dpkg -i debs/ocl-icd*deb
- 编译libfreenect2
$ cd ~/libfreenect2
$ mkdir build && cd build
$ cmake ..
$ make
$ make install
- 如果想指定安装目录:
$ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
- 建立别名
$ cd ~/libfreenect2
$ sudo cp platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
- 重插kinect2,即可识别。
- 运行kinect2
$ cd ~/libfreenect2/build
$ ./bin/Protonect
Version: 0.2.0
Environment variables: LOGFILE=<protonect.log>
Usage: ./Protonect [-gpu=<id>] [gl | cl | clkde | cuda | cudakde | cpu] [<device serial>]
[-noviewer] [-norgb | -nodepth] [-help] [-version]
[-frames <number of frames to process>]
To pause and unpause: pkill -USR1 Protonect
[Info] [Freenect2Impl] enumerating devices...
[Info] [Freenect2Impl] 8 usb devices connected
[Info] [Freenect2Impl] found valid Kinect v2 @2:5 with serial 152816533647
[Info] [Freenect2Impl] found 1 devices
[Info] [Freenect2DeviceImpl] opening...
[Info] [Freenect2DeviceImpl] transfer pool sizes rgb: 20*16384 ir: 60*8*33792
[Info] [Freenect2DeviceImpl] opened
[Info] [Freenect2DeviceImpl] starting...
[Debug] [Freenect2DeviceImpl] status 0x090000: 1024
[Debug] [Freenect2DeviceImpl] status 0x090000: 9729
[Debug] [Freenect2DeviceImpl] status 0x090000: 9731
[Info] [Freenect2DeviceImpl] submitting rgb transfers...
[Info] [Freenect2DeviceImpl] submitting depth transfers...
[Info] [Freenect2DeviceImpl] started
device serial: 152816533647
device firmware: 4.0.3917.0
[Debug] [DepthPacketStreamParser] not all subsequences received 0
[Info] [OpenGLDepthPacketProcessor] avg. time: 10.7364ms -> ~93.1415Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 10.7091ms -> ~93.3786Hz
[Info] [TurboJpegRgbPacketProcessor] avg. time: 23.9899ms -> ~41.6842Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 10.3339ms -> ~96.7689Hz
[Info] [OpenGLDepthPacketProcessor] avg. time: 10.2979ms -> ~97.1069Hz
[Info] [TurboJpegRgbPacketProcessor] avg. time: 20.9942ms -> ~47.6321Hz
- 无错误,显示图像
iai_kinect2安装
- 安装iai_kinect2
$ cd ~/catkin_ws/src/
$ git clone https://github.com/code-iai/iai_kinect2.git
$ cd iai_kinect2
$ rosdep install -r --from-paths .
$ cd ~/catkin_ws
$ catkin_make -DCMAKE_BUILD_TYPE="Release"
测试使用
- 新终端,执行roscore
$ roscore
- 新终端,执行
$ roslaunch kinect2_bridge kinect2_bridge.launch
- 注意:程序默认使用GPU,使用没有GPU的电脑启动可能会出现报错,但若出现报错,可参考下面配置修改
$ rosed kinect2_bridge kinect2_bridge.launch
//修改以下两个参数
<arg name="depth_method" default="cpu"/>
<arg name="reg_method" default="cpu"/>
- 如果是英伟达系列的开发板可以使用cuda启动
$ rosed kinect2_bridge kinect2_bridge.launch
//修改以下两个参数
<arg name="depth_method" default="cuda"/>
<arg name="reg_method" default="cpu"/>
- 新终端,执行
$ rosrun kinect2_viewer save_seq hd cloud
参考资料
- https://openkinect.github.io/libfreenect2/
- http://blog.csdn.net/sunbibei/article/details/51594824
- http://www.cnblogs.com/hitcm/p/5118196.html
- http://www.cnblogs.com/qzwblog/p/5612509.html
获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号