使用iai_kinect2:
https://blog.csdn.net/sunbibei/article/details/51594824
在ubuntu18.04上安装ROS:
https://blog.csdn.net/qq_16481211/article/details/81137830
可以参照官网安装 (http://wiki.ros.org/melodic/Installation/Ubuntu)
在ubuntu18.04版本上只能安装 ROS Melodic
#Setup your sources.list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
#Setup your keys
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
#installation
sudo apt update
#recommand
sudo apt install ros-melodic-desktop-full
#other options can see the websitehttp://wiki.ros.org/melodic/Installation/Ubuntu
#initialize rosdep
sudo rosdep init
rosdep update
#environment setup
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
庆幸装下来没有什么问题
参考github上的安装说明,我删除了一些18.04用不到的语句,有需要的话可以直接去看原说明文档
git clone https://github.com/OpenKinect/libfreenect2.git
cd libfreenect2
cd depends; ./download_debs_trusty.sh
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libturbojpeg0-dev
sudo apt-get install libglfw3-dev
sudo apt-get install beignet-dev
# echo 0 >/sys/module/i915/parameters/enable_cmd_parser
is needed. See more known issues at https://www.freedesktop.org/wiki/Software/Beignet/.apt-get install opencl-headers
.mkdir -p /etc/OpenCL/vendors; echo /usr/lib/arm-linux-gnueabihf/mali-egl/libmali.so >/etc/OpenCL/vendors/mali.icd; apt-get install opencl-headers
.clinfo
to verify if you have correctly set up the OpenCL stack.apt-get install cuda
, use sudo prime-select intel
to use Intel GPU for desktop.sudo apt-get install libva-dev libjpeg-dev
sudo apt-get install libopenni2-dev
cd depends
previously, cd ..
back to the libfreenect2 root directory first.) mkdir build && cd build
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.sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
, then replug the Kinect../bin/Protonect
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.进入libfreenect2/build/bin可以看到编译好的Protonect,连接好kinect2
在命令行输入 ./Protonnect
可以得到kinect的实时画面了
参考github官网
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"
这里注意一下,我安装的ROS虽然自动装了catkin但是没有构建自己的catkin workspace
$ mkdir ~/catkin_ws && cd catkin_ws
$ mkdir src && cd src
$ catkin_init_workspace
$ cd ~/catkin_ws/
$ catkin_make
$ source ~/catkin_ws/devel/setup.bash
$ echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
$ echo $ROS_PACKAGE_PATH
然后就可以按照iai_kinect2的安装说明一步一步来了
之一一下,在执行
rosdep install -r --from-paths .
时,运行结果会报如下错误,直接忽略就好,这是因为需要的package正是我们现在安装的
第一次走到catkin_make DCMAKE_BUILD_TYPE="Release"这一步,我出现一个错误
找不到Eigen/Geometry,根据报错的提醒找到自己这个库的位置,去相应的源文件里修改一下路径就好
我这里是在iai_kinect2/kinect2_registration/src/depth_registration_cpu.h中第一个include加上eigen3就好了,修改后为
#include
补充一下查看自己的eigen安装位置
dpkg -L libeigen3-dev
会出现这个所有所在路径,自己找到需要的复制即可
#使用roslaunch发起Kinect2的相关节点(记得连接好kinect)
roslaunch kinect2_bridge kinect2_bridge.launch
#使用rostopic list查看该节点发布出来的topic
rostopic list
#开启一个窗口查看kinect2获得的图像,后面的sd和cloud是自己选择的参数
rosrun kinect2_viewer kinect2_viewer sd cloud
#点击显示出来的窗口,按下“S”或者空格键就可以保存你之前选择好的参数对应的图像了,
#默认保存在catkin_ws下
保存四张图
cloud.pcd
depth.png
color.jpg
depth_colored.png
命名从0000开始,同一窗口不断按空格就0001,0002依次保存下去,重新run的话在新窗口又是从0000开始保存
在控制窗口可以使用ctrl+c 关闭节点
在iai_kinect2/kinect2_viewer/src/下打开viewer.cpp可以去查看对应的源码来了解对应参数的意义
摘录自大神小贝也沉默的评论:
1、hd 表示1920*1080的分辨率,qhd表示960*540的分辨率,sd表示512*424的分辨率;
2、在saveCloudAndImages函数中, 是使用cv::imwrite(colorName, color, params);来保存图片的, 其中第二个参数就是待保存的图片, 格式是cv::Mat. 在调用saveCloudAndImages函数的前一句话中, 使用cv::resize将图片改成所想要的尺寸即可.
//...省略部分
for(size_t i = 1; i < (size_t)argc; ++i)
{
std::string param(argv[i]);
if(param == "-h" || param == "--help" || param == "-?" || param == "--?")
{
help(argv[0]);
ros::shutdown();
return 0;
}
else if(param == "qhd")
{
topicColor = K2_TOPIC_QHD K2_TOPIC_IMAGE_COLOR K2_TOPIC_IMAGE_RECT;
topicDepth = K2_TOPIC_QHD K2_TOPIC_IMAGE_DEPTH K2_TOPIC_IMAGE_RECT;
}
else if(param == "hd")
{
topicColor = K2_TOPIC_HD K2_TOPIC_IMAGE_COLOR K2_TOPIC_IMAGE_RECT;
topicDepth = K2_TOPIC_HD K2_TOPIC_IMAGE_DEPTH K2_TOPIC_IMAGE_RECT;
}
else if(param == "ir")
{
topicColor = K2_TOPIC_SD K2_TOPIC_IMAGE_IR K2_TOPIC_IMAGE_RECT;
topicDepth = K2_TOPIC_SD K2_TOPIC_IMAGE_DEPTH K2_TOPIC_IMAGE_RECT;
}
else if(param == "sd")
{
topicColor = K2_TOPIC_SD K2_TOPIC_IMAGE_COLOR K2_TOPIC_IMAGE_RECT;
topicDepth = K2_TOPIC_SD K2_TOPIC_IMAGE_DEPTH K2_TOPIC_IMAGE_RECT;
}
else if(param == "approx")
{
useExact = false;
}
else if(param == "compressed")
{
useCompressed = true;
}
else if(param == "image")
{
mode = Receiver::IMAGE;
}
else if(param == "cloud")
{
mode = Receiver::CLOUD;
}
else if(param == "both")
{
mode = Receiver::BOTH;
}
else
{
ns = param;
}
}
**补充一下,自己后面编译别的库给这个iai_kienct2整得用不了;在经过系列排查发现了最终问题所在----boost版本
不知道是和opencv还是pcl编译时候整的,总之在 x86_64-linux-gnu目录下有一个libboost=1.65.1,在usr/local/lib目录下有一个libboost=1.69.0这两个冲突了,在把catkin_ws 删除后,重新建立,然后在编译的时候指代清楚编译使用的库就可以了,之前那句编译的话就是下面这句就可以了。
catkin_make -DCMAKE_BUILD_TYPE="Release"
-DBOOST_ROOT=/usr/lib/x_86_64-linux-gnu
**如果在ros在新的终端操作过程中出现找不到package或者说你的文件不对啥的,先尝试一下
source ~/catkin_ws/devel/setup.bash
把ros的工作目录写到当前的base中
按照博主的教程修改好程序后,第一次编译出现错误
[make]*** No rule to make target
把catkin_ws下的build和devel文件夹删除整个iai_kinect2全部重新编译即可
然后运行,检测是否成功,在终端再次打开bridge
roslaunch kinect2_bridge kinect2_bridge
新开一个终端
rosrun kinect2_viewer save_seq
按下b 开始保存
按下e 停止保存