以下的操作是在一个全新安装的Ubuntu 14.04
系统上进行的,目前已知在安装了ROS
的系统上并且已经安装过ROS
版本的Kinect V2
驱动的,可能需要先移除以前安装的面向ROS
编译的Kinect V2
驱动才行。
首先是安装配置驱动程序以及运行依赖库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ sudo apt-get update $ sudo apt-get upgrade $ sudo apt-get dist-upgrade $ sudo apt-get install python-opencv $ sudo apt-get install python-dev $ sudo apt-get install python-pip $ sudo pip install openni $ sudo apt-get install git |
参照libfreenect2 install linux的说明安装驱动
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
$ cd ~ $ git clone https://github.com/OpenKinect/libfreenect2.git $ cd libfreenect2 $ cd depends; ./download_debs_trusty.sh $ sudo dpkg -i debs/libusb*deb $ sudo apt-get install build-essential cmake pkg-config #如果没有配置ROS源,则使用这个源,否则不需要此步骤 $ sudo apt-add-repository ppa:deb-rob/ros-trusty && sudo apt-get update $ sudo apt-get install libopenni2-dev $ sudo apt-get install libjpeg-dev $ sudo apt-get install libturbojpeg $ sudo apt-get install libgl1-mesa-dev $ sudo apt-get install ocl-icd-opencl-dev #如果要启用CUDA的支持,只能是从nvidia官网下载安装最新版本才行,apt安装的版本会缺少 “ helper_math.h ” # $ wget https://developer.nvidia.com/compute/cuda/8.0/Prod2/local_installers/cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64-deb # $ sudo apt-get update # $ sudo apt-get install cuda $ cd .. $ git clean -xfd $ mkdir build && cd build ##如果在安装过ROS的系统上执行,并且已经通过ROS安装过libfreenect2驱动,可能下面的要调整成“cmake .. -DCMAKE_INSTALL_PREFIX=/usr/” 才能成功覆盖已经安装过的文件 $ cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/ $ make $ sudo make install |
安装Python
扩展
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ cd ~ $ sudo pip install cython $ sudo pip install numpy $ git clone https://github.com/remexre/pyfreenect2.git $ cd pyfreenect2 $ sudo python setup.py install $ sudo apt-get install gfortran $ sudo apt-get install libopenblas-dev $ sudo apt-get install liblapack-dev $ sudo pip install scipy |
Python
例子如下:
1 2 3 |
$ cd ~/pyfreenect2 $ python test.py |
注意,如果编译的时候出现如下错误:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
[ 5%] Building NVCC (Device) object CMakeFiles/cuda_compile.dir/src/./cuda_compile_generated_cuda_kde_depth_packet_processor.cu.o nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning). ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1346): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1346): error: explicit type is missing ("int" assumed) /home/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1346): error: expected a "{" ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1349): warning: missing return statement at end of non-void function "libfreenect2::CudaKdeDepthPacketProcessor" ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1351): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1353): error: identifier "impl_" is undefined /home/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1356): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1358): error: a nonstatic member reference must be relative to a specific object ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1360): error: identifier "impl_" is undefined ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1363): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1365): error: identifier "impl_" is undefined ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1369): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1371): error: identifier "impl_" is undefined ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1378): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1380): error: identifier "impl_" is undefined ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1383): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1385): error: identifier "impl_" is undefined ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1388): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1390): error: identifier "listener_" is undefined ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1393): error: identifier "impl_" is undefined ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1415): error: name followed by "::" must be a class or namespace name ~/libfreenect2/src/cuda_kde_depth_packet_processor.cu(1417): error: identifier "impl_" is undefined ~/longsky/libfreenect2/src/cuda_kde_depth_packet_processor.cu(413): warning: function "calculatePhaseUnwrappingVarDirect" was declared but never referenced 21 errors detected in the compilation of "/tmp/tmpxft_00004ae7_00000000-7_cuda_kde_depth_packet_processor.cpp1.ii". CMake Error at cuda_compile_generated_cuda_kde_depth_packet_processor.cu.o.cmake:264 (message): Error generating file ~/libfreenect2/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 |
则该现象出现的原因是首先参照
1 |
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 |
进行了编译,并且编译的时候是没有开启CUDA
支持的。
然后执行了
1 |
$ make install |
因此在~/libfreenect2/include/libfreenect2/
下面已经生成了config.h
,export.h
这两个文件。
然后又按照我们这里的
1 |
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/ |
重新编译,并且这次开启了CUDA
支持,导致GCC
在编译的时候使用了我们在~/libfreenect2/build/libfreenect2/
下面生成的config.h
,export.h
这两个文件,而NVCC
却使用了~/libfreenect2/include/libfreenect2/
下面的config.h
,export.h
进行编译,导致上面的错误发生。
因此删除全部的临时文件,然后再次重新编译即可。