Ubuntu14.04下搭建Kinect V2的环境以及出现的问题解决方案

请各位注意是kinect V2,kinect有两个版本,V1和V2


一、安装

1、Download libfreenect2 source

git clone git@github.com:DongdongBai/libfreenect2.git
cd libfreenect2

2、Download upgrade deb files

cd depends; ./download_debs_trusty.sh

3、Install build tools

sudo apt-get install build-essential cmake pkg-config

4、先安装Nvidia显卡驱动和cuda,然后源码编译Opencv(本步骤的顺序不可以颠倒,因为Opencv在编译时会查找显卡驱动的版本(是使用集成显卡还是独立显卡呢,以及独立显卡驱动的版本),如果先装Opencv,则Opencv会使用系统的默认的继承显卡驱动,后面安装Nvidia驱动将导致Opencv无法正常使用)

5、Install libusb. The version must be >= 1.0.20.

sudo dpkg -i debs/libusb*deb

6、Install TurboJPEG

sudo apt-get install libturbojpeg libjpeg-turbo8-dev

7、 Install OpenGL

sudo dpkg -i debs/libglfw3*deb
sudo apt-get install -f
sudo apt-get install libgl1-mesa-dri-lts-vivid

如果最后一步出现依赖错误,直接忽略,无需做任何处理

8、Build

cd ..
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 -DENABLE_CXX11=ON
make
make install

9、执行Cmake时出现

CMake Warning at CMakeLists.txt:405 (ADD_LIBRARY):
  Cannot generate a safe runtime search path for target freenect2 because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libOpenCL.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /usr/local/cuda-7.5/lib64

  Some of these libraries may not be found correctly.


CMake Warning at CMakeLists.txt:451 (ADD_LIBRARY):
  Cannot generate a safe runtime search path for target freenect2-openni2
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libOpenCL.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /usr/local/cuda-7.5/lib64

  Some of these libraries may not be found correctly.


CMake Warning at examples/CMakeLists.txt:76 (ADD_EXECUTABLE):
  Cannot generate a safe runtime search path for target Protonect because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libOpenCL.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /usr/local/cuda-7.5/lib64

  Some of these libraries may not be found correctly.

解决方法:在项目的cmake_modules文件夹中的FindOpenCL.cmake中添加下面两句话即可(本教程中clone源代码的CMakeLists.txt已经做了更改,不回出现上述问题,请放心使用):

SET(OpenCL_INCLUDE_DIR /usr/local/cuda/include/ )
SET(OpenCL_LIBRARY  /usr/local/cuda-7.5/lib64/libOpenCL.so)

10、编译时如果出现以下错误:


/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: identifier "nullptr" is undefined

/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432): error: expected a ";"

/usr/include/x86_64-linux-gnu/c++/4.8/bits/c++config.h(190): error: expected a ";"

/usr/include/c++/4.8/exception(63): error: expected a ";"

/usr/include/c++/4.8/exception(68): error: expected a ";"

/usr/include/c++/4.8/exception(76): error: expected a ";"

/usr/include/c++/4.8/exception(83): error: expected a ";"

/usr/include/c++/4.8/exception(93): error: expected a "{"

/usr/include/c++/4.8/bits/exception_ptr.h(64): error: function "std::current_exception" returns incomplete type "std::__exception_ptr::exception_ptr"

/usr/include/c++/4.8/bits/exception_ptr.h(64): error: expected a "{"

/usr/include/c++/4.8/bits/exception_ptr.h(79): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(81): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(82): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(84): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(86): error: declaration is incompatible with previous "std::current_exception"
(64): here

/usr/include/c++/4.8/bits/exception_ptr.h(86): error: use of a local type to declare a function

/usr/include/c++/4.8/bits/exception_ptr.h(86): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(87): error: use of a local type to declare a function

/usr/include/c++/4.8/bits/exception_ptr.h(90): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(92): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(95): error: incomplete type is not allowed

/usr/include/c++/4.8/bits/exception_ptr.h(95): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(116): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(126): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(143): error: use of a local type to declare a function

/usr/include/c++/4.8/bits/exception_ptr.h(144): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(147): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(152): error: use of a local type to declare a function

/usr/include/c++/4.8/bits/exception_ptr.h(153): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(156): error: use of a local type to declare a function

/usr/include/c++/4.8/bits/exception_ptr.h(157): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(160): error: use of a local type to declare a function

/usr/include/c++/4.8/bits/exception_ptr.h(161): error: expected a ";"

/usr/include/c++/4.8/bits/exception_ptr.h(169): error: expected a ";"

/usr/include/c++/4.8/bits/nested_exception.h(57): error: incomplete type is not allowed

/usr/include/c++/4.8/bits/nested_exception.h(60): error: expected a ";"

/usr/include/c++/4.8/bits/nested_exception.h(66): error: expected a ";"

/usr/include/c++/4.8/bits/nested_exception.h(70): error: identifier "rethrow_exception" is undefined

/usr/include/c++/4.8/bits/nested_exception.h(73): error: function "std::nested_exception::nested_ptr" returns incomplete type "std::__exception_ptr::exception_ptr"

/usr/include/c++/4.8/new(95): error: expected a "{"

/usr/include/c++/4.8/new(110): error: identifier "__p" is undefined

/usr/include/c++/4.8/new(111): error: expected a "{"

/usr/include/c++/4.8/new(115): error: expected a "{"

/usr/include/c++/4.8/new(116): error: expected a "{"

/usr/local/cuda-7.5/include/common_functions.h(102): warning: exception specification is incompatible with that of previous function "operator new[](std::size_t, void *)"
/usr/include/c++/4.8/new(111): here

/usr/local/cuda-7.5/include/common_functions.h(103): warning: exception specification is incompatible with that of previous function "operator delete(void *, void *)"
/usr/include/c++/4.8/new(115): here

/usr/local/cuda-7.5/include/common_functions.h(104): warning: exception specification is incompatible with that of previous function "operator delete[](void *, void *)"
/usr/include/c++/4.8/new(116): here

/usr/include/c++/4.8/bits/cpp_type_traits.h(184): error: identifier "char16_t" is undefined

/usr/include/c++/4.8/bits/cpp_type_traits.h(191): error: identifier "char32_t" is undefined

/usr/include/c++/4.8/bits/cpp_type_traits.h(191): error: class "std::__is_integer<>" has already been defined

/usr/include/c++/4.8/bits/cpp_type_traits.h(314): error: namespace "std::__gnu_cxx" has no member "__normal_iterator"

/usr/include/c++/4.8/bits/cpp_type_traits.h(314): error: expected a ">"

/usr/include/c++/4.8/cmath(80): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(80): error: expected a ";"

/usr/include/c++/4.8/cmath(105): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(105): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(105): error: expected a ";"

/usr/include/c++/4.8/cmath(124): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(124): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(124): error: expected a ";"

/usr/include/c++/4.8/cmath(143): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(143): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(143): error: expected a ";"

/usr/include/c++/4.8/cmath(162): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(162): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(162): error: expected a ";"

/usr/include/c++/4.8/cmath(183): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(183): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(183): error: expected a ";"

/usr/include/c++/4.8/cmath(202): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(202): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(202): error: expected a ";"

/usr/include/c++/4.8/cmath(221): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(221): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(221): error: expected a ";"

/usr/include/c++/4.8/cmath(240): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(240): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(240): error: expected a ";"

/usr/include/c++/4.8/cmath(259): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(259): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(259): error: expected a ";"

/usr/include/c++/4.8/cmath(278): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(278): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(278): error: expected a ";"

/usr/include/c++/4.8/cmath(297): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(297): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(297): error: expected a ";"

/usr/include/c++/4.8/cmath(328): error: "constexpr" is not a function or static data member

/usr/include/c++/4.8/cmath(337): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(337): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(337): error: expected a ";"

/usr/include/c++/4.8/cmath(356): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(356): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(356): error: expected a ";"

/usr/include/c++/4.8/cmath(375): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(375): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(375): error: expected a ";"

/usr/include/c++/4.8/cmath(406): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(406): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(406): error: expected a ";"

/usr/include/c++/4.8/cmath(443): error: inline specifier allowed on function declarations only

/usr/include/c++/4.8/cmath(443): error: variable "std::constexpr" has already been defined

/usr/include/c++/4.8/cmath(443): error: expected a ";"

Error limit reached.
100 errors detected in the compilation of "/tmp/tmpxft_00001206_00000000-7_cuda_kde_depth_packet_processor.cpp1.ii".
Compilation terminated.
CMake Error at cuda_compile_generated_cuda_kde_depth_packet_processor.cu.o.cmake:264 (message):
  Error generating file
  /home/bdd/libfreenect2-master/build/CMakeFiles/cuda_compile.dir/src/./cuda_compile_generated_cuda_kde_depth_packet_processor.cu.o


make[2]: *** [CMakeFiles/cuda_compile.dir/src/./cuda_compile_generated_cuda_kde_depth_packet_processor.cu.o] Error 1
make[1]: *** [CMakeFiles/freenect2.dir/all] Error 2
make: *** [all] Error 2

将项目中的cuda关闭即可,即将CMakeLists.txt中的第35行的OPTION(ENABLE_CUDA “Enable CUDA support” ON)的ON改为OFF即可(本教程中clone源代码的CMakeLists.txt已经做了更改,不回出现上述问题,请放心使用)。


二、验证安装是否成功及问题解决方法

在build下面有个bin文件夹,放置生成的输出文件,插上kinect,然后运行。此时黄灯变成白色的,表示有驱动。注意:只能用于USB3的接口,好在台式机和笔记本都有3.0的口。

./bin/Protonect gl
./bin/Protonect cl
./bin/Protonect cpu

但是如果提示权限不够,failed to open Kinect V2 Access denied,设定执行:sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/, 然后重新插拔Kinect2.


Ros接口安装

1、对于已经安装了Ros Indigo的Ubuntu14.04来说,使用下面的命令

cd ~/catkin_ws/src/
git clone [email protected]:DongdongBai/iai_kinect2.git
cd iai_kinect2
sudo rosdep install -r --from-paths .
cd ~/catkin_ws
catkin_make -DCMAKE_BUILD_TYPE="Release"
rospack profile

注意:针对于上述命令中最后一行指令, 需要说明的是, 如果前面libfreenect2你安装的位置不是$HOME/freenect2或/usr/local这两个标准路径下下, 需要提供参数指定libfreenect2所在路径:

catkin_make -Dfreenect2_DIR=path_to_freenect2/lib/cmake/freenect2 -DCMAKE_BUILD_TYPE="Release"

2、sudo rosdep install -r –from-paths . 出现如下问题:

ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies (ROS distro is not set. Make sure `ROS_DISTRO` environment variable is set, or use `--rosdistro` option to specify the distro, e.g. `--rosdistro indigo`):
kinect2_viewer: Cannot locate rosdep definition for [cv_bridge]
kinect2_registration: Cannot locate rosdep definition for [cv_bridge]
kinect2_bridge: Cannot locate rosdep definition for [cv_bridge]
kinect2_calibration: Cannot locate rosdep definition for [cv_bridge]
Continuing to install resolvable dependencies...
#All required rosdeps installed successfully

这个问题是正常情况,不是错误,请大家直接忽视!

3、接下来可以测试了。

roslaunch kinect2_bridge kinect2_bridge.launch

然后重新开一个新的终端

rosrun kinect2_viewer kinect2_viewer

显示如下图所示。Good Luck and enjoy it!

你可能感兴趣的:(机器学习,ROS,解决方案)