Ubuntu下Kinectv2配置

安装Intel OpenCL支持(可选,我的是Intel内置显卡)1

这里下载Intel® Code Builder for OpenCL™ API 2015 for Ubuntu* (64-bit)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
sudo apt-get install -y rpm alien libnuma1

tar -xvf intel_code_builder_for_opencl_2015_ubuntu_5.0.0.43_x64.tgz
cd intel_code_builder_for_opencl_2015_ubuntu_5.0.0.43_x64

sudo rpm --import PUBLIC_KEY.PUB
cd rpm

sudo fakeroot alien --to-deb opencl-1.2-base-5.0.0.43-1.x86_64.rpm
sudo fakeroot alien --to-deb opencl-1.2-intel-cpu-5.0.0.43-1.x86_64.rpm

sudo dpkg -i opencl-1.2-base_5.0.0.43-2_amd64.deb
sudo dpkg -i opencl-1.2-intel-cpu_5.0.0.43-2_amd64.deb

sudo fakeroot alien --to-deb opencl-1.2-devel-5.0.0.43-1.x86_64.rpm
sudo fakeroot alien --to-deb opencl-1.2-intel-devel-5.0.0.43-1.x86_64.rpm

sudo dpkg -i opencl-1.2-devel_5.0.0.43-2_amd64.deb
sudo dpkg -i opencl-1.2-intel-devel_5.0.0.43-2_amd64.deb

The above installs the library files and installable client driver registration in /opt/intel/opencl-1.2-5.0.0.43. Two more steps were needed to run an OpenCL program.

Add library to search path:

1
sudo gedit /etc/ld.so.conf.d/intelOpenCL.conf


Add the line:

1
/opt/intel/opencl-1.2-5.0.0.43/lib64

Link to the intel icd file in the expected location:

1
2
3
4
5
sudo mkdir /etc/OpenCL
sudo mkdir /etc/OpenCL/vendors

sudo ln /opt/intel/opencl-1.2-5.0.0.43/etc/intel64.icd /etc/OpenCL/vendors/intel64.icd
sudo ln -s /opt/intel/opencl-1.2-5.0.0.43/lib64/libOpenCL.so /usr/lib/libOpenCL.so

还需要将opencl_include_dir放到系统的环境中:

1
sudo gedit ~/.bashrc

填入:

1
export PATH="/opt/intel/opencl-1.2-sdk-5.0.0.43/include:$PATH"
1
2
source ~/.bashrc
sudo ldconfig

测试结果:

1
2
sudo apt-get install clinfo
sudo clinfo

安装NVIDIA的支持(可选)

首先根据这里安装CUDA。

下载Kinectv2的开源驱动libfreenect22,解压缩:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
git clone https://github.com/OpenKinect/libfreenect2.git
cd depends
sh ./download_debs_trusty.sh
sh ./install_ubuntu.sh

sudo dpkg -i libglfw3*_3.0.4-1_*.deb
sudo apt-get install build-essential cmake pkg-config libturbojpeg libjpeg-turbo8-dev mesa-common-dev freeglut3-dev libxrandr-dev libxi-dev

sudo dpkg -i debs/libusb*deb
sudo dpkg -i debs/{libva,i965}*deb; sudo apt-get install -f

sudo apt-add-repository ppa:deb-rob/ros-trusty && sudo apt-get update
cd

cd ..
mkdir build && cd build
cmake .. -DENABLE_CXX11=ON
make
sudo make install

sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/

如在编译时出现错误:

1
2
3
4
5
6
7
Linking CXX shared library lib/libfreenect2.so
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libturbojpeg.a(libturbojpeg_la-turbojpeg.o): relocation R_X86_64_32 against `.data' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libturbojpeg.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make[2]: *** [lib/libfreenect2.so.0.2.0] Error 1
make[1]: *** [CMakeFiles/freenect2.dir/all] Error 2
make: *** [all] Error 2

可重新安装libturbojpeg:

1
sudo apt-get install libturbojpeg

升级内核(14.04):

1
sudo apt-get install linux-generic-lts-wily

or:

1
sudo apt-get install inux-generic-lts-vivid

测试:

1
./bin/Protonect

另外:

libusb可以这么安装:

1
2
3
sudo apt-add-repository ppa:floe/libusb
sudo apt-get update
sudo apt-get install libusb-1.0-0-dev

GLFW3可以这么安装3

1
2
3
4
5
echo "deb http://ppa.launchpad.net/keithw/glfw3/>ubuntu trusty main" | sudo tee -a /etc/apt/sources.list.d/fillwave_ext.list
echo "deb-src http://ppa.launchpad.net/keithw/glfw3/ubuntu trusty main" | sudo tee -a /etc/>apt/sources.list.d/fillwave_ext.list

sudo apt-get update
sudo apt-get install libglfw3-dev

安装iai_kinect2

This is a collection of tools and libraries for a ROS Interface to the Kinect One (Kinect v2).

1
2
3
4
5
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
git clone https://github.com/code-iai/iai_kinect2.git
cd iai_kinect2
rosdep install -r --from-paths .

此时可能会显示有关[kinect2_bridge] and [depth_registration]的错误,不用理它。

1
2
cd ~/catkin_ws
catkin_make -DCMAKE_BUILD_TYPE="Release"

测试

打开一个窗口:

1
roscoe

打开另外一个窗口:

1
2
3
cd ~/catkin_ws/
source devel/setup.sh
roslaunch kinect2_bridge kinect2_bridge.launch

再打开另外一个窗口:

1
2
3
cd ~/catkin_ws/
source devel/setup.bash
rosrun kinect2_viewer kinect2_viewer

安装Pangolin

1
2
3
4
5
6
7
sudo apt-get install libglew-dev libboost-dev libboost-thread-dev libboost-filesystem-dev
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake -DCPP11_NO_BOOST=1 ..
make -j

ORB_SLAM2

1
2
3
4
5
6
sudo apt-get install libblas-dev liblapack-dev

git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
cd ORB_SLAM2
chmod +x build.sh
./build.sh

  1. https://software.intel.com/en-us/forums/opencl/topic/390630↩︎

  2. https://github.com/OpenKinect/libfreenect2↩︎

  3. https://github.com/filipwasil/fillwave/issues/58↩︎