安装libfreenect2
github上的readme写的很详细了,一步步参考着来
- 下载
git clone https://github.com/OpenKinect/libfreenect2.git
- 安装依赖
这一步参考官方说明即可。https://github.com/OpenKinect/libfreenect2
稍稍记录一下,我当时是按着别人的博客装的,也都差不多,但是要注意18.04版本要sudo apt-get install libturbojpeg0-dev,否则会报错找不到tubojpeg。
但是我这边还会说找不到 libva、liba-drm、tegrajpeg,看有人的博客上说那是因为没装libturbojpeg0-dev,但是我装完还是这样,先不管了,也没报错
- 编译
mkdir build && cd build
#cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2 // 这是官方给出的
cmake .. -DENABLE_CXX11=ON //我是没有设置这个路径,建议按上边的来
make
sudo make install
#You need to specify cmake -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2 for CMake based third-party application to find libfreenect2.
- 这里再稍稍记录一下cmake时候碰到的大坑,就是我把libfreenect2放在了以下含有中文的文件夹下,导致出现
error: Cannot open file /home/y/工具/libfreenect2/build/CMakeDoxyfile.tpl for writing
CMake Error at /home/y/.local/lib/python2.7/site-packages/cmake/data/share/cmake-3.18/Modules/FindDoxygen.cmake:689 (message):
Unable to generate Doxyfile template: 1
Call Stack (most recent call first):
doc/CMakeLists.txt:1 (find_package)- 这个问题,一直搞不好,后来换了文件名之后,就好了。
- cmkae时关于OpenGL的警告:
CMake Warning (dev) at /home/y/.local/lib/python2.7/site-packages/cmake/data/share/cmake-3.18/Modules/FindOpenGL.cmake:305(message): Policy CMP0072 is not set: FindOpenGL prefers GLVND bydefault when available. Run “cmake --help-policy CMP0072” for policy details. Use the cmake_policy command to set the policy and suppress this warning.- 解决办法:
在CMakeLists加上
if (POLICY CMP0072)
set(OpenGL_GL_PREFERENCE LEGACY)
endif()
- 还有一个问题是在make install 时遇到的,大概意思是无法从哪里复制到哪里,这是因为权限不够,要记得到make install 时加上sudo,这样就没问题了。
- Set up udev rules for device access:
sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
, then replug the Kinect.重新插拔Kinect2. - 测试
Run the test program: build目录下
./bin/Protonect
./bin/Protonect cl
./bin/Protonect gl
./bin/Protonect cpu
安装iai-kinect2
- 下载、编译
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" //出现100%就是成功了
- 在运行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]
kinect2_bridge: Cannot locate rosdep definition for [kinect2_registration]
kinect2_calibration: Cannot locate rosdep definition for [kinect2_bridge]
Continuing to install resolvable dependencies...
解决办法:可以忽略,不想忽略可以参考https://answers.ros.org/question/237451/run-rosdep-install-r-from-paths-error-when-i-install-iai_kinect2/
原因:
(参考:https://github.com/code-iai/iai_kinect2/issues/296)
Maybe reading the README:
Note: rosdep will output errors on not being able to locate [kinect2_bridge] and [depth_registration].
That is fine because they are all part of the iai_kinect2 package and rosdep does not know these packages.
-
catkin_make -DCMAKE_BUILD_TYPE=“Release”,这里要注意,如果不是在那两个默认路径下(官方给出的cmake时的路径HOME/freenect2 和 /usr/local/),就要修改这句为
catkin_make -DCMAKE_BUILD_TYPE="Release" -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2
-
我在
catkin_make -DCMAKE_BUILD_TYPE="Release"
这里出错,根据报错信息:
可以看出来是opencv版本的问题
解决办法:将iai-kinect2下的kinect2_bridge、kinect2_calibration等四个文件夹下的CMakeLists里的find_package(OpenCV REQUIRED) 修改为find_package(OpenCV 3 REQUIRED),指定opencv版本为我安装的3.2.0 。
然后重新运行catkin_make命令,虽然这个时候有很多warning,但是最后100%了
- 运行
roslaunch kinect2_bridge kinect2_bridge.launch //在src下运行
- 这个问题是发生在解决catkin_make之前的,那个没问题的话,这里应该也没问题
[ERROR] [1605063781.417458728]: Failed to load nodelet [/kinect2_bridge] of type [kinect2_bridge/kinect2_bridge_nodelet] even after refreshing the cache: Could not find library corresponding to plugin kinect2_bridge/kinect2_bridge_nodelet. Make sure the plugin description XML file has the correct name of the library and that the library actually exists.- 这个问题就比较明显了,找不到设备,原因是我忘记插电了
[ERROR] [1605065349.856412161]: [Kinect2Bridge::initDevice] no Kinect2 devices found!
[ERROR] [1605065349.858918791]: [Kinect2Bridge::start] Initialization failed!
[FATAL] [1605065349.938611904]: Failed to load nodelet ‘/kinect2_bridgeof type
kinect2_bridge/kinect2_bridge_nodeletto manager
kinect2’
[kinect2_bridge-3] process has died [pid 4297, exit code 255, cmd /opt/ros/melodic/lib/nodelet/nodelet load kinect2_bridge/kinect2_bridge_nodelet kinect2 __name:=kinect2_bridge __log:=/home/y/.ros/log/0eea346c-23ce-11eb-a8bc-002b676588cd/kinect2_bridge-3.log].
log file: /home/y/.ros/log/0eea346c-23ce-11eb-a8bc-002b676588cd/kinect2_bridge-3*.log
当终端中提示 [ INFO] [1605065815.596049840]: [Kinect2Bridge::callbackStatus] client connected. starting device...
,表示设备已经就绪了
重新打开一个终端,输入rostopic list
,可以看到:
/kinect2/bond
/kinect2/hd/camera_info
/kinect2/hd/image_color
/kinect2/hd/image_color/compressed
/kinect2/hd/image_color_rect
/kinect2/hd/image_color_rect/compressed
/kinect2/hd/image_depth_rect
/kinect2/hd/image_depth_rect/compressed
/kinect2/hd/image_mono
/kinect2/hd/image_mono/compressed
/kinect2/hd/image_mono_rect
/kinect2/hd/image_mono_rect/compressed
/kinect2/hd/points
/kinect2/qhd/camera_info
/kinect2/qhd/image_color
/kinect2/qhd/image_color/compressed
/kinect2/qhd/image_color_rect
/kinect2/qhd/image_color_rect/compressed
/kinect2/qhd/image_depth_rect
/kinect2/qhd/image_depth_rect/compressed
/kinect2/qhd/image_mono
/kinect2/qhd/image_mono/compressed
/kinect2/qhd/image_mono_rect
/kinect2/qhd/image_mono_rect/compressed
/kinect2/qhd/points
/kinect2/sd/camera_info
/kinect2/sd/image_color_rect
/kinect2/sd/image_color_rect/compressed
/kinect2/sd/image_depth
/kinect2/sd/image_depth/compressed
/kinect2/sd/image_depth_rect
/kinect2/sd/image_depth_rect/compressed
/kinect2/sd/image_ir
/kinect2/sd/image_ir/compressed
/kinect2/sd/image_ir_rect
/kinect2/sd/image_ir_rect/compressed
/kinect2/sd/points
/rosout
/rosout_agg
然后可以通过 rosrun kinect2_viewer kinect2_viewer
查看图像