Pointpillars(四) 结合ROS来实现激光雷达点云物体检测

参考以下链接: 

基于ROS的自动驾驶--激光雷达点云物体检测项目实战

原文链接:https://blog.youkuaiyun.com/jin15203846657/article/details/125870504

基于ROS的自动驾驶 激光雷达点云物体检测 项目实战_caffe 训练激光点云-优快云博客

前言:

基于Apollo的preceptionAutowarelidar_apollo_cnn_seg_detect模块,并详细记录ROS系统上进行实时检测全部流程和踩坑,文章最后附上rosbag和rosbag的制作方法。

环境

RTX 2060(后面关于算力)

ubuntu 18.04

ROS melodic (ubuntu 18.04安装ROS melodic可以参看我这篇文章ubuntu 18.04安装ROS系统)

CUDA 10.0

cudnn 7.6.5

caffe

cmake 3.18.2(不能低于3.12.2)

opencv 3.2.0

安装

ubuntu 18.04、ROS melodic 、CUDA 10.0、cudnn 7.6.5安装在此就不赘述。

caffe安装

分步执行,安装依赖项

sudo apt-get install  -y libopencv-devsudo apt-get install -y build-essential cmake git pkg-configsudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compilersudo apt-get install -y liblapack-devsudo apt-get install -y libatlas-base-dev sudo apt-get install -y --no-install-recommends libboost-all-devsudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-devsudo apt-get install -y python-numpy python-scipysudo apt-get install -y python3-pipsudo apt-get install -y python3-numpy python3-scipy

下载caffe开源软件项目(一定要在下载到home文件目录下)

cd ~git clone https://github.com/BVLC/caffe

图片

进入caffe/python/目录下,执行下面的命令,下载依赖的软件

cd caffe/python/for req in $(cat requirements.txt); do pip3 install $req; done

图片

下载本项目源码:

git clone https://github.com/AbangLZU/cnn_seg_lidar.git

将下载下来源码里面的Makefile.config复制到caffe文件夹下

图片

图片

更改Makefile.config里面的部分内容

CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \             -gencode arch=compute_35,code=sm_35 \             -gencode arch=compute_50,code=sm_50 \             -gencode arch=compute_52,code=sm_52 \             -gencode arch=compute_61,code=sm_61

改为(这部分算力根据自己显卡型号来哈):

CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \             -gencode arch=compute_35,code=sm_35 \             -gencode arch=compute_50,code=sm_50 \             -gencode arch=compute_52,code=sm_52 \             -gencode arch=compute_60,code=sm_60 \             -gencode arch=compute_61,code=sm_61 \             -gencode arch=compute_61,code=compute_61

图片

    改为(根据自己OpenCV版本来,我的是3.2.0):OPENCV_VERSION :=3

    注:如果不清楚自己opencv版本型号,输入下面命令产看版本:

    pkg-config opencv --modversion

    图片

    编译caffe

    make -j8make distribute

    成功后如下图所示:

    图片

    再编译本项目

    首先要对源码做一部分修改(修改数据的topic,以便检测算法能读取数据):

    修改cnn_seg_lidar/src/lidar_cnn_seg_detect/nodes/cnn_segmentation.cpp

    图片

    如果不知道topic是啥,先运行下rosbag包,打开rviz看下

    图片

    修改完后就可以再项目文件夹cnn_seg_lidar下编译了:

    catkin_make

    可能会报错:

    -- Could NOT find jsk_recognition_msgs (missing: jsk_recognition_msgs_DIR)-- Could not find the required component 'jsk_recognition_msgs'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.CMake Error at /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):  Could not find a package configuration file provided by  "jsk_recognition_msgs" with any of the following names:
        jsk_recognition_msgsConfig.cmake    jsk_recognition_msgs-config.cmake

    解决方法:​​​​​​​

    sudo apt-get install ros-melodic-jsk-recognition-msgs sudo apt-get install ros-melodic-jsk-rviz-plugins

    此时再catkin_make就没问题了,成功如下:

    图片

    然后我们下面开始制做rosbag

    使用kitti2bag项目将kitti 的raw data转化为rosbag
    其中需要将kitti2bag项目中的kitti2bag/kitti2bag.py 里面fill pcl msg中的反射强度i改成intensity,如下所示:​​​​​​​

    fields = [PointField('x', 0, PointField.FLOAT32, 1),            PointField('y', 4, PointField.FLOAT32, 1),            PointField('z', 8, PointField.FLOAT32, 1),            PointField('intensity', 12, PointField.FLOAT32, 1)]

    图片

    下载kitti raw data中的一部分就行(如2011_09_26_drive_0101_sync.zip数据文件包括点云、图像等和2011_09_26_calib.zip标定文件,这两个组合起来用的,所以前面的数字要对应,不能不匹配),放在kitti2bag文件夹下

    图片

    解压这两个文件:​​​​​​​

    unzip 2011_09_26_drive_0101_sync.zipunzip 2011_09_26_calib.zip

    图片

    开始转换:

    python -m kitti2bag -t 2011_09_26 -r 0101 raw_synced .

    可能会遇到下面错误:

    ImportError: dynamic module does not define module export function (PyInit__tf2)

    这是因为tf2是为了Python2写的,不适用于Python3,所以需要吧python换成ubuntu系统自带的2.7版本

    图片

    此时在转换应该就没问题了,成功后界面如下:

    图片

    在kitti2bag文件夹下应该就有了rosbag:

    图片

    启动激光雷达点云三维目标检测

    先启动ROS

    roscore

    再循环播放rosbag数据:

    rosbag play kitti_2011_09_26_drive_0101_synced.bag -l --clock

    图片

    然后在cnn_seg_lidar文件夹下打开终端:​​​​​​​

    source devel/setup.bashroslaunch lidar_cnn_seg_detect lidar_cnn_seg_detect.launch 

    cnn_seg_lidar文件夹下新开终端打开rviz:

    rviz -d src/lidar_cnn_seg_detect/rviz_config/lidar_detect.rviz

    点击Add(我是因为提前开了,所以有画面,正常情况下刚打开rviz是没这样的画面的)

    图片

    选择如下

    图片

    更改这里,就会显示雷达画面:

    图片

    刚开始点云的点很小,可以改下尺寸:

    图片

    最终检测画面如下所示:

    图片

    至此全部完成。

    测试rosbag链接:

    链接:百度网盘 请输入提取码https://pan.baidu.com/s/17Nqm4VzwoJxBGZOl2tnQwQ
    提取码:k1us

    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值