Ubuntu下ZED CAMERA的安装配置

系统环境

  • 型号:Thinkpad 460p
  • 显卡:GeForce 940MX & Intel HD Graphics 530
  • 系统:Ubuntu 14.04.5 LTS
  • 内核:4.4.0-31-generic

前期准备

1
2
3
4
sudo apt-get update
sudo apt-get upgrade

sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libtbb2 libeigen2-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev git

安装显卡驱动

CUDA 7.5自带的驱动在Ubuntu 14.04.5(4.4 kernel)上会出现安装错误:

1
The driver installation is unable to locate the kernel source.

这是由于CUDA 7.5的驱动是针对3.xx kernels的,所以需要安装较新的驱动1

这里下载安装包cuda_8.0.61_375.26_linux.run

这里下载安装包cuda_7.5.18_linux.run

1
sudo apt-get install linux-headers-$(uname -r) g++

关掉开源的Nouveau驱动2

1
lsmod | grep nouveau #检测Nouveau是否开启,有输出则开启,无输出则为开启

如果Nouveau开启:

1
sudo gedit /etc/modprobe.d/blacklist-nouveau.conf

在创建的文件中输入以下内容关闭掉Nouveau

1
2
blacklist nouveau
options nouveau modeset=0

更新list,使得更改生效

1
sudo update-initramfs -u

重启电脑,进入登录界面的时候,先不要登录进入桌面3,按Ctrl+Alt+F1进入命令行界面,关闭图形化界面:

1
sudo service lightdm stop

安装驱动

继续上个步骤,在命令行界面中进入到cuda_8.0.61_375.26_linux.run所在文件夹,运行:

1
2
chmod +x cuda_8.0.61_375.26_linux.run
sudo sh cuda_8.0.61_375.26_linux.run

注意我们这里只选择安装Driver!

安装CUDA 7.5

1
2
chmod +x cuda_7.5.18_linux.run
sudo sh cuda_7.5.18_linux.run

需要gcc 4.8版本的编译器 注意不要安装openGL,不然会遇到循环登录的问题!

重启图形化界面:

1
sudo service lightdm start

配置环境:

1
sudo gedit ~/.bashrc

添加:

1
2
export PATH=/usr/local/cuda-7.5/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-7.5/lib64:$LD_LIBRARY_PATH

重启电脑,执行:

1
ls /dev/nvidia*

应出现如:

1
/dev/nvidia0  /dev/nvidiactl  /dev/nvidia-uvm  /dev/nvidia-uvm-tools

"/dev/nvidia*: No such file or directory"错误

1
sudo gedit /etc/rc.local

去掉第一行中#!/bin/sh -e-e, 并且在exit 0前添加4

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
/sbin/modprobe nvidia

if [ "$?" -eq 0 ]; then
# Count the number of NVIDIA controllers found.
NVDEVS=`lspci | grep -i NVIDIA`
N3D=`echo "$NVDEVS" | grep "3D controller" | wc -l`
NVGA=`echo "$NVDEVS" | grep "VGA compatible controller" | wc -l`

N=`expr $N3D + $NVGA - 1`
for i in `seq 0 $N`; do
mknod -m 666 /dev/nvidia$i c 195 $i
done

mknod -m 666 /dev/nvidiactl c 195 255

else
exit 1
fi

/sbin/modprobe nvidia-uvm

if [ "$?" -eq 0 ]; then
# Find out the major device number used by the nvidia-uvm driver
D=`grep nvidia-uvm /proc/devices | awk '{print $1}'`

mknod -m 666 /dev/nvidia-uvm c $D 0
else
exit 1
fi

测试

输入:

1
cat /proc/driver/nvidia/version

显示:

1
2
NVRM version: NVIDIA UNIX x86_64 Kernel Module  375.26  Thu Dec  8 18:36:43 PST 2016
GCC version: gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)

输入:

1
nvcc -V

输出:

1
2
3
4
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2015 NVIDIA Corporation
Built on Tue_Aug_11_14:27:32_CDT_2015
Cuda compilation tools, release 7.5, V7.5.17

编译sample

NVIDIA_CUDA-8.0_Samples文件夹下执行:

1
make

进入NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release文件夹,运行:

1
./deviceQuery 

删除CUDA的方法

当出现问题需要重装时,可输入:

1
2
3
sudo /usr/local/cuda-7.5/bin/uninstall_cuda_7.5.pl
sudo /usr/bin/nvidia-uninstall
sudo apt-get remove --purge nvidia-*

升级gcc到4.9(可选)

Ubuntu系统默认的是gcc 4.8,版本比较老,在使用时候可能会导致一些错误,所以将gcc升级到4.9版本,并且将4.9作为默认编译器。

查看当前版本:

1
gcc -v

安装gcc 4.9:

1
2
3
4
5
6
7
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.9 g++-4.9
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9


sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8

显示和选择使用版本:

1
sudo update-alternatives --config gcc

安装libfreenect2(可选)

由于将来需要使用Kinect2,所以顺带将相应的驱动也装上了:

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
sudo apt-get install libopenni2-dev

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
./bin/Protonect

安装OpenCV 2.4.10

修改/modules/gpu/src/graphcuts.cpp的内容,将:

1
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)

修改为:

1
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

运行:

1
2
3
4
5
6
7
8
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D CUDA_GENERATION=Kepler -D WITH_TBB=ON -D WITH_LIBV4L=ON ..
make -j7
sudo make install

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

卸载OpenCV的方法

1
>sudo make uninstall

安装Pangolin(可选)

1
2
3
4
5
6
7
8
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

安装ROS Indigo5

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo sh -c '. /etc/lsb-release && echo "deb http://mirror.sysu.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://pool.sks-keyservers.net --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116

sudo apt-get update
sudo apt-get install ros-indigo-desktop-full

sudo rosdep init
rosdep update

echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
source ~/.bashrc

sudo apt-get install python-rosinstall

Depends错误

如果在安装时出现Depends: ros-indigo-simulators but it is not going to be installed的错误(安装gazebo2导致的错误),可以先下载老版本的libsdformat-dev,安装,然后再执行sudo apt-get install ros-indigo-desktop-full

安装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"

"libfreenect2.so: undefined reference to clRetainContext@OPENCL_1.0"错误

这是由于CUDA自带的/usr/local/cuda/lib64/libOpenCL.so和其他库提供的/usr/lib/x86_64-linux-gnu/libOpenCL.so冲突导致6,执行以下命令:

1
sudo apt-get remove nvidia-modprobe opencl-headers

测试

打开一个窗口:

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

安装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

安装OpenCV 3.1

ZED SDK v1.1需要OpenCV 3.1,所以需要再安装一个。在这里下载openCV 3.1版本的源代码。

修改/modules/cudalegacy/src/graphcuts.cpp的内容7,将:

1
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER)

修改为:

1
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)

运行:

1
2
3
4
5
6
7
8
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON ..
make -j7
sudo make install

sudo /bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
sudo ldconfig

查看当前OpenCV版本号

1
pkg-config --modversion opencv  

OpenCV多版本冲突

由于系统安装了两个版本的OpenCV,在编译时有可能会发生以下错误:

1
/usr/bin/ld: warning: libopencv_highgui.so.2.4, needed by /opt/ros/indigo/lib/libcv_bridge.so, may conflict with libopencv_highgui.so.3.1

这时,可以在CMakeLists.txt文件中指定OpenCV所需版本的的build目录路径来解决冲突问题,如8

1
set(OpenCV_DIR "/home/luohanjie/Documents/Software/opencv-2.4.10/build")

安装ZED SDK

这里下载ZED SDK for Linux。

最新的v2.0版本在Ubuntu 14.04下无法使用,所以使用v1.1版本。

1
2
chmod +x ZED_SDK_Linux_x86_64_v1.1.0
./ZED_SDK_Linux_x86_64_v1.1.0.run

输入 q 退出 license agreement。

安装zed-ros-wrapper

1
2
3
4
5
6
cd ~/catkin_ws/src
git clone https://github.com/stereolabs/zed-ros-wrapper.git
git checkout v1.0.0

cd ..
catkin_make

测试

打开一个窗口,执行:

1
roscore

打开另外一个窗口,执行:

1
2
3
cd ~/catkin_ws
source ./devel/setup.bash
roslaunch zed_wrapper zed.launch

再打一个窗口:

1
rosrun rviz rviz

Then click on add (bottom left), select the By Topic tab, select point_cloud->cloud->PointCloud2 and click OK9.

运行结果:

Screenshot from 2017-05-15 10:20:10

Launch file parameters

Parameter Description Value
svo_file SVO filename path to an SVO file
resolution ZED Camera resolution '0': HD2K
_ _ '1': HD1080
_ _ '2': HD720
_ _ '3': VGA
quality Disparity Map quality '0': NONE
_ _ '1': PERFORMANCE
_ _ '2': MEDIUM
_ _ '3': QUALITY
sensing_mode Depth sensing mode '0': FILL
_ _ '1': STANDARD
openni_depth_mode Convert depth to 16bit in millimeters '0': 32bit float meters
_ _ '1': 16bit uchar millimeters
frame_rate Rate at which images are published int
rgb_topic Topic to which rgb==default==left images are published string
rgb_cam_info_topic Topic to which rgb==default==left camera info are published string
rgb_frame_id ID specified in the rgb==default==left image message header string
left_topic Topic to which left images are published string
left_cam_info_topic Topic to which left camera info are published string
left_frame_id ID specified in the left image message header string
right_topic Topic to which right images are published string
right_cam_info_topic Topic to which right camera info are published string
right_frame_id ID specified in the right image message header string
depth_topic Topic to which depth map images are published string
depth_cam_info_topic Topic to which depth camera info are published string
depth_frame_id ID specified in the depth image message header string
point_cloud_topic Topic to which point clouds are published string
cloud_frame_id ID specified in the point cloud message header string
odometry_topic Topic to which odometry is published string
odometry_frame_id ID specified in the odometry message header string
odometry_transform_frame_id Name of the transformation following the odometry string