Autoware(Vision-detect)的编译、调试、启动

Autoware视觉模块node的编译步骤

I. 创建该模块所需的环境

比如:

  1. vision_segment_enet_detect需要caffe-enet
  2. vision_ssd_detect需要caffe-ssd

以caffe-enet为例:

  1. 在reademe文件中找到相应的caffe源码下载下来(如下图)
    Autoware(Vision-detect)的编译、调试、启动_第1张图片
  2. 下载好之后打开源码根目录下的Makefile文件,查找LIBRARIES,修改该行:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial
  1. 修改源码根目录下的Makefile.config
  1. USE_CUDNN := 1
  2. CUDA_DIR := /usr/local/cuda-9.0 (此处的cuda路径需要修改为自己环境下的正确路径)
  3. INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
    LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu
  1. 在根目录下运行如下命令
make && make distribute
  1. 若编译正常,则环境准备完成~

II. 修改该模块下的package/CMakeList.txt

以vision_segment_enet_detect为例

cmake_minimum_required(VERSION 2.8.12)
project(vision_segment_enet_detect)

FIND_PACKAGE(catkin REQUIRED COMPONENTS
  autoware_build_flags
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  )
FIND_PACKAGE(CUDA)
FIND_PACKAGE(OpenCV REQUIRED)

catkin_package(CATKIN_DEPENDS
  cv_bridge
  image_transport
  roscpp
  sensor_msgs
  )
###########
## Build ##
###########

####################添加进去的####################
#####此处的路径都需要和自己的本地环境对应进行相应的修改####
set(CMAKE_CXX_FLAGS "-O2 -g -Wall ${CMAKE_CXX_FLAGS}")
set(CUDA_FOUND True)
set(CUDA_INCLUDE_DIRS '/usr/local/cuda-9.0/include')
set(CUDA_LIBRARIES '/usr/local/cuda-9.0/lib64')
set(CUDA_CUBLAS_LIBRARIES '/usr/local/cuda-9.0/targets/x86_64-linux/lib')
set(CUDA_curand_LIBRARY '/usr/local/cuda-9.0/doc/man/man7')
################################################

INCLUDE_DIRECTORIES(
  ${catkin_INCLUDE_DIRS}
  )


#####ENET########
##############################ENet's CAFFE FORK NEEDS TO BE PREVIOUSLY COMPILED####################
#需要我们修改的,此处填写第一步编译好的caffe环境路径/distribute
set(ENET_CAFFE_PATH "/home/n6-301/caffe-enet/distribute")
####################################################################################################
if (EXISTS "${ENET_CAFFE_PATH}")

  ADD_EXECUTABLE(vision_segment_enet_detect
    nodes/vision_segment_enet_detect/vision_segment_enet_detect_node.cpp
    nodes/vision_segment_enet_detect/vision_segment_enet_detect.cpp
    )

  link_directories(
                ${CUDA_LIBRARIES}
            ${CUDA_CUBLAS_LIBRARIES}
            ${CUDA_curand_LIBRARY}
    )

  TARGET_LINK_LIBRARIES(vision_segment_enet_detect
    ${catkin_LIBRARIES}
    ${ENET_CAFFE_PATH}/lib/libcaffe.so
    glog
    )

  TARGET_INCLUDE_DIRECTORIES(vision_segment_enet_detect PRIVATE
    ${CUDA_INCLUDE_DIRS}
    ${ENET_CAFFE_PATH}/include
    include
    /usr/local/cuda-9.0/targets/x86_64-linux/include
    )

  ADD_DEPENDENCIES(vision_segment_enet_detect
    ${catkin_EXPORTED_TARGETS}
    )

  install(TARGETS
        vision_segment_enet_detect
        ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
        RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
  )
else ()
  message("' ENet/Caffe' is not installed. 'vision_segment_enet_detect' will not be built.")
endif ()

III. 重新编译Autoware,运行新的node

  1. 在Autoware/ros/src/build目录下运行命令:
make all
  1. 在Autoware/ros/src/build/devel/lib/node_name/下找到node_name的可执行文件拷贝至node相应的位置,在此处以vision_segment_enet_detect为例:
cp /home/n6-301/Autoware/ros/src/build/devel/lib/vision_segment_enet_detec/vision_segment_enet_detec /home/n6-301/Autoware/ros/src/computing/perception/detection/packages/vision_segment_enet_detect/

IV. 启动node

在该模块下的launch文件中有所需model文件和net的文件名,在github或google中搜索下载

  1. 修改launch文件的参数,以vision_segment_enet_detect/launch/vision_segment_enet_detect.launch为例:
<launch>    
        
       
       
    <arg name="network_definition_file" default="/home/n6-301/SSD_300x300/enet_deploy_final.prototxt"/>    
    <arg name="pretrained_model_file" default="/home/n6-301/SSD_300x300/cityscapes_weights.caffemodel"/>    
    <arg name="lookuptable_file" default="/home/n6-301/SSD_300x300/cityscapes19.png"/>
    <arg name="camera_id" default="/" />    
    <arg name="image_src" default="/image_raw"/>
        
    <node pkg="vision_segment_enet_detect" type="vision_segment_enet_detect" name="vision_segment_enet_detect" output="screen">        
        <param name="network_definition_file" type="str" value="$(arg network_definition_file)"/>     
        <param name="pretrained_model_file" type="str" value="$(arg pretrained_model_file)"/>       
        <param name="lookuptable_file" type="str" value="$(arg lookuptable_file)"/>       
        <param name="image_raw_node" type="str" value="$(arg camera_id)$(arg image_src)"/>    
    node>
launch>
  1. 在Atuoware的UI控制界面运行相应的node或者命令行roslaunch启动

若使用命令行启动,可能会遇到找不到package的错误,执行一下命令即可:

source Autoware/ros/devel/setup.bash

命令行启动node

roslaunch package package.launch
例:roslaunch vision_segment_enet_detect vision_segment_enet_detect.launch

Autoware UI启动
Autoware(Vision-detect)的编译、调试、启动_第2张图片

IV. 一切正常可以在rviz中看到想要的识别画面

此处展示的vision_ssd_detect的识别结果,因为vision_segment_enet_detect中使用的是cityscapes_weights的权重(城市道路数据集),不方便室内测试,所以没有展示。
Autoware(Vision-detect)的编译、调试、启动_第3张图片

你可能感兴趣的:(Autoware-vision,自动驾驶)