1.Download libfreenect2 source
git clone https://github.com/OpenKinect/libfreenect2.git
cd libfreenect2
Install build tools
sudo apt-get install build-essential cmake pkg-config
Install libusb. The version must be >= 1.0.20.
sudo apt-get install libusb-1.0-0-dev
Install TurboJPEG
sudo apt-get install libturbojpeg libjpeg-turbo8-dev
Install OpenGL
sudo apt-get install libglfw3-dev
Install OpenNI2 (optional)
sudo apt-get install libopenni2-dev
Install OpenCL (optional)
https://blog.csdn.net/gagabook/article/details/53539823
Build (if you have run cd depends previously, cd .. back to the libfreenect2 root directory first.)
mkdir build && cd build
# cmake .. -DCMAKE_INSTALL_PREFIX=$/usr/local/freenect2 -DENABLE_CXX11=ON
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
make
make install
You need to specify cmake -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2
for CMake based third-party application to find libfreenect2.
针对上面cmake命令的说明, 第一个参数, 是特别指定安装的位置, 你也可以指定别的你觉得高兴的地方, 但一般标准的路径是上述示例路径或者/usr/local。 第二个参数是增加C++11的支持。
Set up udev rules for device access: sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
, then replug the Kinect.
Run OpenNI2 test (optional): sudo apt-get install openni2-utils && sudo make install-openni2 && NiViewer2
. Environment variable LIBFREENECT2_PIPELINE can be set to cl, cuda, etc to specify the pipeline.
设定udev rules: sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/, 然后重新插拔Kinect2,一切搞定
相机,必须插在USB3.0的插口上!
Run the test program: sudo ./bin/Protonect
注意:这里不加sudo权限可能会导致提示找不到设备
Run OpenNI2 test (optional): sudo apt-get install openni2-utils && sudo make install-openni2 && NiViewer2
. Environment variable LIBFREENECT2_PIPELINE
can be set to cl
, cuda
, etc to specify the pipeline.
2.Install IAI Kinect2
利用命令行从Github上面下载工程源码到工作空间内src文件夹内:
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"
针对于上述命令中最后一行指令, 需要说明的是, 如果前面libfreenect2你安装的位置不是标准的两个路径下, 需要提供参数指定libfreenect2所在路径:
catkin_make -Dfreenect2_DIR=path/to/freenect2/lib/cmake/freenect2 -DCMAKE_BUILD_TYPE="Release"
在执行rosdep install -r --from-paths .
时可能汇报错:
ERROR: the following packages/stacks could not have their rosdep keys resolved
to system dependencies:
kinect2_viewer: Cannot locate rosdep definition for [kinect2_bridge]
iai_kinect2: Cannot locate rosdep definition for [kinect2_registration]
kinect2_calibration: Cannot locate rosdep definition for [kinect2_bridge]
kinect2_bridge: Cannot locate rosdep definition for [kinect2_registration]
Continuing to install resolvable dependencies...
#All required rosdeps installed successfully
没有关系,这些依赖库就是我们之后要安装的,忽视就好了.
在进行catkin_make -DCMAKE_BUILD_TYPE="Release"
时提示:
CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
CMake 3.8 or higher is required. You are running version 3.5.1
-- Configuring incomplete, errors occurred!
Invoking "cmake" failed
升级cmake的方法参照:https://blog.csdn.net/li872149120/article/details/77892127
设置环境变量:
source devel/setup.bash
接下来进行测试,打开kinect接口:
roslaunch kinect2_bridge kinect2_bridge.launch
新建一个终端,显示运行图像
rosrun kinect2_viewer kinect2_viewer
图片上传好慢,就不贴图了,如果各位安装过程中遇到任何问题请在评论区与我讨论,谢谢!