Advertisement

OpenCV使用CNN进行目标检测

阅读量:

OpenCV使用CNN进行目标检测

  • 使用CNN进行目标检测
    • 建造Building
    • 物体检测
    • 改变门槛
    • 影像分类

使用CNN进行目标检测

建造Building

生成‘dnn_objectect’模块的示例样本;配置BUILD_EXAMPLES=ONCMake并构建如下目标(针对Linux系统)。

该模型用于实现图像分类功能。
该模型用于执行目标检测任务。
从下载权重文件以及模型定义文件 opencv_extra/dnn_objdetect

物体检测

复制代码
    example_dnn_objdetect_obj_detect  <model-definition-file>  <model-weights-file>  <test-image>

全部配备有Intel® Core™2 i3-4005U CPU @ 1.70GHz(不带GPU)的笔记本电脑均在进行运行。

该模型非常快,0.172091平均只需几秒钟即可预测多个边界框。

复制代码
    <bin_path>/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/bus.jpg
    Total objects detected: 1 in 0.201276 seconds
    ------
    Class: bus
    Probability: 0.701829
    Co-ordinates: 0 32 415 244
    ------
在这里插入图片描述
复制代码
    <bin_path>/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/bus.jpg
    Total objects detected: 1 in 0.201276 seconds
    ------
    Class: bus
    Probability: 0.701829
    Co-ordinates: 0 32 415 244
    ------
在这里插入图片描述
复制代码
    <bin_path>/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/cat.jpg
    Total objects detected: 1 in 0.190335 seconds
    ------
    Class: cat
    Probability: 0.703465
    Co-ordinates: 34 0 381 282
    ------
在这里插入图片描述
复制代码
    <bin_path>/example_dnn_objdetect_obj_detect  SqueezeDet_deploy.prototxt  SqueezeDet.caffemodel  tutorials/images/persons_mutli.jpg
    Total objects detected: 2 in 0.169152 seconds
    ------
    Class: person
    Probability: 0.737349
    Co-ordinates: 160 67 313 363
    ------
    Class: person
    Probability: 0.720328
    Co-ordinates: 187 198 222 323
    ------
在这里插入图片描述

继续使用其他图像运行模型!

改变门槛

在默认设置下,该模型将识别边界框时的检测阈值设为0.53。在过滤阶段时预测到一定数量的边界框时,请注意您可以通过指定相关参数的数值来自主调节这一关键指标;例如:threshold

复制代码
    <bin_path>/example_dnn_objdetect_obj_detect  <model-definition-file>  <model-weights-file>  <test-image> <threshold>

将阈值更改为0.0,将产生以下结果:

在这里插入图片描述

似乎没有帮助!

影像分类

复制代码
    example_dnn_objdetect_image_classification  <model-definition-file>  <model-weights-file>  <test-image>

模型的大小为4.9MB,只需花费0.136401秒即可对图像进行分类。

在示例上运行模型会产生以下结果:

复制代码
    <bin_path>/example_dnn_objdetect_image_classification  SqueezeNet_deploy.prototxt  SqueezeNet.caffemodel  tutorials/images/aeroplane.jpg
    Best class Index: 404
    Time taken: 0.137722
    Probability: 77.1757

查看synset_words.txt,预测的类属于airliner

复制代码
    <bin_path>/example_dnn_objdetect_image_classification  SqueezeNet_deploy.prototxt  SqueezeNet.caffemodel  tutorials/images/cat.jpg
    Best class Index: 285
    Time taken: 0.136401
    Probability: 40.7111

这属于此类: Egyptian cat

复制代码
    <bin_path>/example_dnn_objdetect_image_classification  SqueezeNet_deploy.prototxt  SqueezeNet.caffemodel  tutorials/images/space_shuttle.jpg
    Best class Index: 812
    Time taken: 0.137792
    Probability: 15.8467

这属于此类: space shuttle

全部评论 (0)

还没有任何评论哟~