TA的每日心情 | 开心 2018-9-6 15:08 |
---|
签到天数: 11 天 连续签到: 1 天 [LV.3]偶尔看看II
|
本帖最后由 阿莫斯 于 2018-8-15 10:51 编辑
基于ROS智能陪伴扫地机:2.源码浅析及目标检测实例
一、角蜂鸟程序架构和流程
思路:以linux系统Python开发环境的example示例分析程序流程,再ROS环境下将以上example示例再移植一遍;
为什么这样操作?
首先本人是图像识别初学者对整个图像识别流程不太熟悉,
其次官网中对Python的例程资料最多,ROS实例的教程官网还未做出,因此只能自己撸代码;
linux系统Python开发环境为例:
- 人脸检测器
- 物体检测器
- 情景记录器
- 图像识别器(底层API教程)
- 人脸检测+识别器(双角蜂鸟集联教程)
- OCR 文字检测识别 (进行中)
拓展到ROS环境下实例:
<占位符>后续填充
二、分析SungemSDK-ROS文件架构
- <font size="1">├── object_msgs
- │ ├── CMakeLists.txt
- │ ├── msg
- │ │ ├── ObjectInBox.msg
- │ │ ├── Object.msg
- │ │ ├── ObjectsInBoxes.msg
- │ │ └── Objects.msg
- │ └── package.xml
- ├── Readme.md
- └── ros_horned_sungem
- ├── horned_sungem_example
- │ ├── CMakeLists.txt
- │ ├── package.xml
- │ └── src
- │ ├── stream_classification.cpp
- │ └── stream_detection.cpp
- ├── horned_sungem_launch
- │ ├── CMakeLists.txt
- │ ├── config
- │ │ ├── alexnet.yaml
- │ │ ├── googlenet.yaml
- │ │ ├── inception_v1.yaml
- │ │ ├── inception_v2.yaml
- │ │ ├── inception_v3.yaml
- │ │ ├── inception_v4.yaml
- │ │ ├── mobilenetssd.yaml
- │ │ ├── mobilenet.yaml
- │ │ ├── squeezenet.yaml
- │ │ └── yolo.yaml
- │ ├── launch
- │ │ ├── hs_camera.launch
- │ │ ├── hs_classification_example.launch
- │ │ ├── hs_detection_example.launch
- │ │ └── includes
- │ │ ├── hs_stream_classification.launch
- │ │ └── hs_stream_detection.launch
- │ └── package.xml
- ├── horned_sungem_lib
- │ ├── CMakeLists.txt
- │ ├── include
- │ │ └── horned_sungem_lib
- │ │ ├── connect.h
- │ │ ├── device.h
- │ │ ├── exception.h
- │ │ ├── exception_util.h
- │ │ ├── graph.h
- │ │ ├── hs_cpp.h
- │ │ ├── hs_manager.h
- │ │ ├── result.h
- │ │ └── tensor.h
- │ ├── package.xml
- │ └── src
- │ ├── connect.cpp
- │ ├── device.cpp
- │ ├── exception.cpp
- │ ├── exception_util.cpp
- │ ├── graph.cpp
- │ ├── hs_manager.cpp
- │ ├── result.cpp
- │ └── tensor.cpp
- └── horned_sungem_stream
- ├── CMakeLists.txt
- ├── include
- │ └── horned_sungem_stream
- │ └── hs_nodelet.h
- ├── nodelet_plugins.xml
- ├── package.xml
- └── src
- └── hs_nodelet.cpp
- 17 directories, 52 files</font>
复制代码 2.1 SungemSDK-ROS一级目录下内容是:- object_msgs 包中使用的消息类型信息;
- Readme.md 提示文档
- ros_horned_sungem 核心部分:角蜂鸟包
2.2 ros_horned_sungem对应的二级目录下内容是:
- horned_sungem_example ,
- horned_sungem_launch ,类似批处理的launch启动文件
- horned_sungem_lib ,
- horned_sungem_stream,
三、分析horned_sungem_launch包3.1.初步分析
官网教程中调用的第一个launch文件是
- roslaunch horned_sungem_launch hs_camera.launch cnn_type:=googlenet camera:=hs pixels:=360
复制代码 调用的包是horned_sungem_launch,启动的文件是hs_camera.launch,
设置的参数是
- cnn_type:模型名称,googlenet表示模模型是图像识别模型
- camera : 摄像头类型,hs表示摄像头为角蜂鸟摄像头
- pixels :像素,360表示为360p
关于整个系统的参数有哪些可以用rostopic list查看
- amos@amos-desktop:~/catkin_ws/src/SungemSDK-ROS/ros_horned_sungem$ rosparam list
- /horned_sungem_nodelet/horned_sungem_stream/camera
- /horned_sungem_nodelet/horned_sungem_stream/category_file_path
- /horned_sungem_nodelet/horned_sungem_stream/channel1_mean
- /horned_sungem_nodelet/horned_sungem_stream/channel2_mean
- /horned_sungem_nodelet/horned_sungem_stream/channel3_mean
- /horned_sungem_nodelet/horned_sungem_stream/cnn_type
- /horned_sungem_nodelet/horned_sungem_stream/graph_file_path
- /horned_sungem_nodelet/horned_sungem_stream/log_level
- /horned_sungem_nodelet/horned_sungem_stream/max_device_number
- /horned_sungem_nodelet/horned_sungem_stream/network_dimension
- /horned_sungem_nodelet/horned_sungem_stream/pixels
- /horned_sungem_nodelet/horned_sungem_stream/scale
- /horned_sungem_nodelet/horned_sungem_stream/start_device_index
- /horned_sungem_nodelet/horned_sungem_stream/top_n
- /hs/camera/image_raw/compressed/format
- /hs/camera/image_raw/compressed/jpeg_quality
- /hs/camera/image_raw/compressed/png_level
- /hs/camera/image_raw/compressedDepth/depth_max
- /hs/camera/image_raw/compressedDepth/depth_quantization
- /hs/camera/image_raw/compressedDepth/png_level
- /hs/camera/image_raw/theora/keyframe_frequency
- /hs/camera/image_raw/theora/optimize_for
- /hs/camera/image_raw/theora/quality
- /hs/camera/image_raw/theora/target_bitrate
- /rosdistro
- /roslaunch/uris/host_amos_desktop__42426
- /rosversion
- /run_id
复制代码
启动摄像头
从直观的功能角度来看,它是启动了摄像头和配置了某一种卷积神经网络算法(cnn),打开了设备并加装了摄像头拍摄的图片!
官网教程中调用的第二个launch文件是
- roslaunch horned_sungem_launch hs_classification_example.launch camera_topic:="/hs/camera/image_raw"
复制代码 调用的包是horned_sungem_launch,启动的文件是hs_classification_example.launch,
设置的参数是
- camera_topic:摄像头话题,/hs/camera/image_raw表示从角蜂鸟摄像头获取图片;
启动图片阅读器
终端虽然会报错,但是iamge_viewer可以正常启动!不会影响ROS的正常使用,可以不用处理!
(补充:libEGL问题是树莓派会有的问题,https://pi3d.github.io/html/FAQ.html )
从直观的功能角度来看,它打了image_viewer窗口,将摄像头拍照和检测结果同步显示出!
这仅仅是官方的一个ROS执行示例,也是唯一示例!
那如果用户想体验和执行其他的类似Python教程的中的示例该怎么办呢?或者更简单的实现官网图片中的yolo卷积神经网络算法呢?
实测:yolo替代googlenet
- roslaunch horned_sungem_launch hs_camera.launch cnn_type:=yolo camera:=hs pixels:=360
复制代码- roslaunch horned_sungem_launch hs_classification_example.launch camera_topic:="/hs/camera/image_raw"
复制代码 以上操作虽然不报错,但是iamge_viewer不会启动,不知道是什么情况!!!那么只有通过分析源码,来一探其用法了!
3.2.进一步分析源码
以上两次指令执行的包都是horned_sungem_launch,其实它并不是源码功能包,这是一个启动文件包,它可以一次启动多个功能包,有点类似批处理功能,同时能够进行参数配置(缺省时为默认配置),同时可以修改节点的名称!下面具体分析上面两条指令的内容:
3.2.1 hs_camera.launch
具体分析是如何执行的!
文件在~/catkin_ws/src/SungemSDK-ROS/ros_horned_sungem/horned_sungem_launch/launch/路径下,内容如下:
代码解释:代码可以分成四段
- ①<!-- 一堆参数配置 -->
- ②<!-- 启动摄像头节点 -->
- ③<!-- 启动角蜂鸟节点 -->
<!-- 分类处理 --> 或<!-- 检测处理 -->
1).参数配置:
- <arg name="manager" default="hornedsungem_manager" />
复制代码- <arg name="param_file" value="$(find horned_sungem_launch)/config/googlenet.yaml" if="$(eval cnn_type == 'googlenet')"/>
复制代码 前面为参数名,后面对参数名的赋值,这个参数配置是全局的,有直接对参数赋值的,也有通过加载参数配置文件yaml文件进行赋值的!
8种cnn模式对应了8份yaml配置文件,实际使用时选择其一!特别注意:output_topic参数的赋值根据cnn的模式分了两类:classified_objects和detected_objects,此次带过,后续详解;
以上参数配置分别对识别的模式,摄像头的像素等方面进行了配置!
2).启动摄像头节点
- <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
复制代码 3).启动角蜂鸟节点
- <node pkg="nodelet" type="nodelet" name="$(arg manager)" args="manager" output="screen" />
复制代码 分类再一次出现,也是根据对角蜂鸟模式cnn_type的选择,因此将其暂时分为两大类classification和detection,二选一:
- <!-- for classification -->
- <group if="$(eval cnn_type == 'alexnet' or cnn_type == 'googlenet'
- or cnn_type == 'inception_v1' or cnn_type == 'inception_v2'
- or cnn_type == 'inception_v3' or cnn_type == 'inception_v4'
- or cnn_type == 'mobilenet' or cnn_type == 'squeezenet')">
- ......
- <!-- for detection -->
- <group if="$(eval cnn_type == 'mobilenetssd' or cnn_type == 'yolo')">
复制代码 这两大类又分别调用了不同的launch文件;
- <include file="$(find horned_sungem_launch)/launch/includes/hs_stream_classification.launch">
复制代码- <include file="$(find horned_sungem_launch)/launch/includes/hs_stream_detection.launch">
复制代码 在此本人小白,觉得有必要科普下Detection和Classification,目标检测是根据阈值获得Bounding box (两类问题),分类检测是将分割后的内容直接进行分类处理(一般是多类问题);目标检测实现给定一幅图像,只需要找到一类目标所在的矩形框 ,例如人脸为目标,框出一幅图片中所有人脸所在的位置,背景为非目标,分类检测根据图像的主要内容进行分类;
还是看图更直观!
detection-classification
a)hs_stream_classification.launch
- <!--
- Copyright (c) 2018 HornedSungem Corporation
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <launch>
- <arg name="manager" />
- <arg name="frame_topic" default="/hs/camera/image_raw" />
- <arg name="output_topic" default="/horned_sungem_nodelet/classified_objects" />
- <arg name="max_device_number" default="255" />
- <arg name="start_device_index" default="0" />
- <arg name="log_level" default="0" />
- <arg name="pixels" default="360" />
- <arg name="camera" default="hs"/>
- <arg name="cnn_type" default="googlenet" />
- <arg name="param_file" default="$(find horned_sungem_launch)/config/googlenet.yaml" />
- <arg name="top_n" default="3" />
- <node pkg="nodelet" type="nodelet" name="horned_sungem_stream"
- args="load horned_sungem_stream/HSNodelet $(arg manager)"
- output="screen">
- <remap from="/hs/camera/image_raw" to="$(arg frame_topic)" />
- <remap from="classified_objects" to="$(arg output_topic)" />
- <param name="max_device_number" value="$(arg max_device_number)" />
- <param name="start_device_index" value="$(arg start_device_index)" />
- <param name="log_level" value="$(arg log_level)" />
- <param name="pixels" value="$(arg pixels)"/>
- <param name="camera" value="$(arg camera)"/>
- <param name="cnn_type" value="$(arg cnn_type)" />
- <param name="top_n" value="$(arg top_n)" />
- <rosparam command="load" file="$(arg param_file)" />
- </node>
- </launch>
复制代码 b)hs_stream_detection.launch
- <!--
- Copyright (c) 2018 HornedSungem Corporation
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <launch>
- <arg name="manager" />
- <arg name="frame_topic" default="/hs/camera/image_raw" />
- <arg name="output_topic" default="/horned_sungem_nodelet/detected_objects" />
- <arg name="max_device_number" default="255" />
- <arg name="start_device_index" default="0" />
- <arg name="log_level" default="0" />
- <arg name="pixels" default="360" />
- <arg name="camera" default="hs"/>
- <arg name="cnn_type" default="mobilenetssd" />
- <arg name="param_file" default="$(find horned_sungem_launch)/config/mobilenetssd.yaml" />
- <arg name="top_n" default="1" />
- <node pkg="nodelet" type="nodelet" name="horned_sungem_stream"
- args="load horned_sungem_stream/HSNodelet $(arg manager)"
- output="screen">
- <remap from="/hs/camera/image_raw" to="$(arg frame_topic)" />
- <remap from="detected_objects" to="$(arg output_topic)" />
- <param name="max_device_number" value="$(arg max_device_number)" />
- <param name="start_device_index" value="$(arg start_device_index)" />
- <param name="log_level" value="$(arg log_level)" />
- <param name="pixels" value="$(arg pixels)"/>
- <param name="camera" value="$(arg camera)"/>
- <param name="cnn_type" value="$(arg cnn_type)" />
- <param name="top_n" value="$(arg top_n)" />
- <rosparam command="load" file="$(arg param_file)" />
- </node>
- </launch>
复制代码 对比以上两个launch文件,其实摄像头方面程序配置相同,仅仅在“cnn_type”和“param_file”存在差异!
- <arg name="cnn_type" default="googlenet" />
- <arg name="param_file" default="$(find horned_sungem_launch)/config/googlenet.yaml" />
复制代码 vs
- <arg name="cnn_type" default="mobilenetssd" />
- <arg name="param_file" default="$(find horned_sungem_launch)/config/mobilenetssd.yaml" />
复制代码
3.2.2 hs_classification_example.launch
- <!--
- Copyright (c) 2018 HornedSungem Corporation
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <launch>
- <arg name="camera_topic" default="/hs/camera/image_raw" />
- <node name="horned_sungem_example_stream_classification" pkg="horned_sungem_example" type="horned_sungem_example_stream_classification" output="screen" >
- <remap from="/hs/camera/image_raw" to="$(arg camera_topic)" />
- </node>
- </launch>
复制代码 该段代码,实现了不使用源码中的节点名,重新创建了一个名为horned_sungem_example_stream_classification的节点!调用的包是horned_sungem_example,可执行文件名为horned_sungem_example_stream_classification!通过重映射将摄像头的图像数据发布到camera_topic,即默认的/hs/camera/image_raw;
这个启动文件实现了将订阅节点horned_sungem_example_stream_classification的视频流输出的功能!
回顾3.1中最后的操作,
- roslaunch horned_sungem_launch hs_camera.launch cnn_type:=yolo camera:=hs pixels:=360
- roslaunch horned_sungem_launch hs_classification_example.launch camera_topic:="/hs/camera/image_raw"
复制代码 这实际上是发布了一个detection的话题,却订阅了一个classification的话题,自然不会有显示结果啦!
通过目录树可知,文件夹下其实还有一个启动文件hs_detection_example.launch
3.2.3 hs_detection_example.launch
- <!--
- Copyright (c) 2018 HornedSungem Corporation
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
- <launch>
- <arg name="camera_topic" default="/hs/camera/image_raw" />
- <node name="horned_sungem_example_stream_detection" pkg="horned_sungem_example" type="horned_sungem_example_stream_detection" output="screen" >
- <remap from="/hs/camera/image_raw" to="$(arg camera_topic)" />
- </node>
- </launch>
复制代码 该段代码实现了不使用源码中的节点名,重新创建了一个名为horned_sungem_example_stream_detection的节点!调用的包是horned_sungem_example,可执行文件名为horned_sungem_example_stream_detection!
通过重映射将摄像头的图像数据发布到camera_topic,即默认的/hs/camera/image_raw;
这个启动文件实现了将订阅节点horned_sungem_example_stream_detection的视频流输出的功能!
因此,如果要使用yolo卷积编码算法实现目标检测,正确操作如下:发布detection的话题,订阅detection的话题
- roslaunch horned_sungem_launch hs_camera.launch cnn_type:=yolo camera:=hs pixels:=360
复制代码- roslaunch horned_sungem_launch hs_detection_example.launch camera_topic:="/hs/camera/image_raw"
复制代码
detection效果
矩形窗口会跟随人脸移动,且会标识出百分比可信度!
回顾整个过程,其实最后的执行结果很简单!可能只需要官网大大说一下就可以实现!
但是通过以上步骤可以加深对程序架构的理解!其他cnn算法实现功能依此类推,只需要注意其属于哪一类即可,下面汇总了cnn所属的类!
(补充目前yolo卷积编码算法tiny yolo v1)
Classification:
- alexnet
- googlenet
- inception_v1
- inception_v2
- inception_v3
- inception_v4
- mobilenet
- squeezenet
Detection:
下一步:分析源码cpp文件
—————————————————————————————————————————————————
参考文献:
目标检测入门之(二)综述(下)
https://blog.csdn.net/weixin_41278720/article/details/81187091
计算机视觉领域不同的方向:目标识别、目标检测、语义分割等
https://blog.csdn.net/u011574296/article/details/78933427
图像分割、图像识别、图像检测的区别
http://blog.sina.com.cn/s/blog_9b8abe6b0102x2hp.html
图像文字识别(OCR)用什么算法小结
http://www.cnblogs.com/ys99/p/9201229.html
图像物体分类与检测算法综述
https://wenku.baidu.com/view/dd75d728240c844768eaee09.html
|
评分
-
查看全部评分
|