Ubuntu16.04+Kinect-v2+RGBD SLAM V2实现
Ubuntu16.04+Kinect-v2+RGBD SLAM V2实现
- 1.安装ROS
 - 2.安装kinect-v2驱动并测试
 - 3. 在ROS中编译iai-kinect2:
 - 4.实现RGBD-SLAM_v2
 
1.安装ROS
1.1 设置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'
    
    
        1.2 设置秘钥key:
    sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
    
    
    
        1.3 更新软件源并安装:
    sudo apt-get update
    
    
        1.4 安装ROS:
    sudo apt-get install ros-kinetic-desktop-full
    
    
        1.5 使ROS包有效:
    apt-cache search ros-kinetic
    
    
        1.6 初始化rosdep:
    sudo rosdep init
    rosdep update
    
    
        1.7 设置环境变量:
    echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    
    
        1.8 安装rosinstall:
    sudo apt-get install python-rosinstall
    
    
        1.9 创建工作目录并设置路径:
    mkdir -p ~/catkin_ws/src
    cd ~/catkin_ws/src
    catkin_init_workspace
    
    
        1.10 设置ros包的环境变量:
    echo “source ~/catkin_ws/devel/setup.bash” >> ~/.bashrc
    source ~/.bashrc
    
    
        或者每次进入catkin_ws目录时输入:
    source devel/setup.bash
    
    
        2.安装kinect-v2驱动并测试
2.1 下载驱动包:
    cd ~/ThirdParty
    git clone https://github.com/OpenKinect/libfreenect2.git  
    cd libfreenect2 
    
    
        2.2 安装依赖:
    sudo apt-get install build-essential cmake pkg-config libusb-1.0-0-dev libturbojpeg libjpeg-turbo8-dev
    sudo apt-get install libglfw3-dev libopenni2-dev
    
    
        2.3 编译构建:
    mkdir build && cd build
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/  
    make
    sudo make install
    
    
        2.4 设置udev规则:
    sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
    
    
        2.5 安装openni2驱动
    sudo apt-get install openni2-utils
    sudo make install-openni2
    
    
        2.6 测试
将Kinect摄像头接入,之后测试命令:
    ./bin/Protonect
    
    
        以上所有步骤如果不出问题,则可以得到以下测试结果:

3. 在ROS中编译iai-kinect2:
3.1 下载源代码
    cd ~/catkin_ws/src/
    git clone https://github.com/code-iai/iai_kinect2.git
    
    
        3.2 编译安装
    cd iai_kinect2
    rosdep install -r --from-paths .
    cd ~/catkin_ws
    catkin_make -DCMAKE_BUILD_TYPE="Release"
    rospack profile
    
    
        3.3 测试是否安装成功
插上kienct2,然后ros
    cd ~/catkin_ws
    roscore
    
    
        然后在另外一个终端:
    roslaunch kinect2_bridge kinect2_bridge.launch publish_tf:=true
    
    
        再打开一个终端:
    rosrun image_view image_view image:=/kinect2/hd/image_color
    
    
        出现以下测试结果:

使用kinect2 提供的viwer显示图像
    rosrun kinect2_viewer kinect2_viewer
    
    
        
按空格或者s键单张采集彩色图、深度图及其对应的点云图图像:

使用rqt_image_view,来显示图像
    rosrun rqt_image_view rqt_image_view
    
    
        
使用rviz显示
    rosrun rviz rviz
    
    
        修改“Fixed Frame”为/kinect2_rgb_optical_frame,接着点击add,选择camera类型。添加成功后选择camera菜单下的Iamge Topic选项,选择 /kinect2/hd/image_color。
接着点击add选择camera类型。添加成功后选择camera菜单下的Iamge Topic选项,选择 /camera/depth/image,如下图所示:
4.实现RGBD-SLAM_v2
4.1下载源代码
    cd ~/catkin_ws/src
    git clone https://github.com/felixendres/rgbdslam_v2
    
    
        4.2 安装g2o
    sudo apt-get install cmake libeigen3-dev libsuitesparse-dev libqt4-dev qt4-qmake libqglviewer-dev qt5-qmake
    cd ~/ThirdParty
    git clone https://github.com/felixendres/g2o
    cd g2o
    mkdir build
    cd build
    cmake ..
    make
    sudo make install
    
    
    

        4.3 安装pcl
下载pcl1.8 https://github.com/PointCloudLibrary/pcl/archive/pcl-1.8.0.tar.gz
进入解压的pcl-pcl-1.8.0目录,打开终端
编译安装
    tar -zxvf pcl-pcl-1.8.0.tar.gz
    cd pcl-pcl-1.8.0 && mkdir build && cd build
    cmake ..
    make
    sudo make install
    
    
        4.4 编译RGBDSLAM
第一步,修改cmakelsits文件
    cd ~/catkin_ws/src/rgbdslam_v2
    gedit CMakeLists.txt
    
    
        将79行pcl1.7改为pcl1.8
    find_package(PCL 1.8 REQUIRED COMPONENTS common io)
    
    
        在最后一行添加
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
    
    
        保存退出。
第二步,编译 siftgpu
    cd ~/catkin_ws/src/rgbdslam_v2/external/SiftGPU
    sudo apt-get install libglew-dev
    sudo apt-get install libdevil1c2 libdevil-dev
    make
    
    
        第三步,编译安装
    cd ~/catkin_ws
    catkin_make
    
    
        4.5基于Kinect v2实时RGBDSLAMv2
建立rgbdslam_kinect2.launch文件
    cd ~/catkin_ws/src/rgbdslam_v2/launch
    touch rgbdslam_kinect2.launch
    gedit rgbdslam_kinect2.launch
    
    
        内容如下
    <!-- This file shows the most important parameters in their default settings,
     to make them easily available for beginners.
     The openni driver has to be started seperately, e.g. with "roslaunch openni_launch openni.launch" -->
    <launch> 
    <node pkg="rgbdslam" type="rgbdslam" name="rgbdslam" cwd="node" required="true" output="screen"> 
     
    <!-- Input data settings-->
     <param name="config/topic_image_mono"              value="/kinect2/qhd/image_color_rect"/> 
    <param name="config/camera_info_topic"             value="/kinect2/qhd/camera_info"/>
     <param name="config/topic_image_depth"             value="/kinect2/qhd/image_depth_rect"/> 
    <param name="config/topic_points"                  value=""/> <!--if empty, poincloud will be reconstructed from image and depth --> 
     
    <!-- These are the default values of some important parameters --> 
    <param name="config/feature_extractor_type"        value="ORB"/><!-- also available: SIFT, SIFTGPU, SURF, SURF128 (extended SURF), ORB. --> 
    <param name="config/feature_detector_type"         value="ORB"/><!-- also available: SIFT, SURF, GFTT (good features to track), ORB. --> 
    <param name="config/detector_grid_resolution"      value="3"/><!-- detect on a 3x3 grid (to spread ORB keypoints and parallelize SIFT and SURF) --> 
    <param name="config/optimizer_skip_step"           value="15"/><!-- optimize only every n-th frame -->
     <param name="config/cloud_creation_skip_step"      value="2"/>
     
    <!-- subsample the images' pixels (in both, width and height), when creating the cloud (and therefore reduce memory consumption) -->
     <param name="config/backend_solver"                value="csparse"/><!-- pcg is faster and good for continuous online optimization, cholmod and csparse are better for offline optimization (without good initial guess)--> <param name="config/pose_relative_to"              value="first"/><!-- optimize only a subset of the graph: "largest_loop" = Everything from the earliest matched frame to the current one. Use "first" to optimize the full graph, "inaffected" to optimize only the frames that were matched (not those inbetween for loops) --> 
    <param name="config/maximum_depth"           value="2"/> <param name="config/subscriber_queue_size"         value="20"/> 
    <param name="config/min_sampled_candidates"        value="30"/><!-- Frame-to-frame comparisons to random frames (big loop closures) -->
     <param name="config/predecessor_candidates"        value="20"/><!-- Frame-to-frame comparisons to sequential frames--> 
    <param name="config/neighbor_candidates"           value="20"/><!-- Frame-to-frame comparisons to graph neighbor frames--> 
    <param name="config/ransac_iterations"             value="140"/> 
    <param name="config/g2o_transformation_refinement"           value="1"/> 
    <param name="config/icp_method"           value="icp"/> <!-- icp, gicp ... --> <!--
    <param name="config/max_rotation_degree"           value="20"/>
    <param name="config/max_translation_meter"           value="0.5"/>
    <param name="config/min_matches"           value="30"/>   
    <param name="config/min_translation_meter"           value="0.05"/>
    <param name="config/min_rotation_degree"           value="3"/>
    <param name="config/g2o_transformation_refinement"           value="2"/>
    <param name="config/min_rotation_degree"           value="10"/>
    <param name="config/matcher_type"         value="SIFTGPU"/>
     --> 
    </node> 
    </launch>
    
    
    

        测试
    roslaunch kinect2_bridge kinect2_bridge.launch
    roslaunch rgbdslam_kinect2.launch
    
    
        参考博客链接:
ros安装:http://wiki.ros.org/kinetic/Installation/Ubuntu
kinect驱动安装:
RGBD SLAM实现:
