这篇文章只是基于OpenCV使用SSD算法执行目标检测;不涉及到SSD的理论原理、不涉及训练过程;也就是说仅仅使用训练好的模型文件基于OpenCV做测试;包括图片和视频;

  只用作笔记,原教程地址:Object detection with deep learning and OpenCV


Single Shot Detectors for Object Detection

  当提到基于深度学习的目标检测算法,大家都多多少少的听说过这三种算法:

 当然了,现在已经是19年了,上面三种算法也已经更新换代了;那之所以还列举出来,想要表达的是这三类算法是相当good,...(完了,装不下去了....)

R-CNN系列检测算法,精确度高,速度慢;

YOLO系列检测算法,速度快,精确度有些欠缺;

SSD取了两者的优点吧。。。。

Deep learning-based object detection with OpenCV

#!/usr/bin/env python
#-*- coding:utf-8 -*-
# @Time : 19-4-24 下午3:52
# @Author : chen """
利用MobileNet SSD + OpenCV中的dnn执行目标检测 python deep_learning_object_detection_cz.py --image images/face_1.jpg \
--prototxt MobileNetSSD_deploy.prototxt.txt \
--model MobileNetSSD_deploy.caffemodel
"""
# 依赖包
import numpy as np
import argparse
import cv2
import time
import pdb # 解析命令行参数
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="path to input image")
ap.add_argument("-p", "--prototxt", required=True, help="path to Caffe 'deploy' prototxt file")
ap.add_argument("-m", "--model", required=True, help="path to Caffe pre-trained model")
ap.add_argument("-c", "--confidence", type=float, default=0.2, help="minimum probability to filter weak detections")
args = vars(ap.parse_args()) # 初始化类标签,然后为每一个类别设置一个颜色值
# 该颜色值是为了在图像中画出矩形框的时候使用
CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat",
"bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
"dog", "horse", "motorbike", "person", "pottedplant", "sheep",
"sofa", "train", "tvmonitor"]
COLORS = np.random.uniform(0, 255, size=(len(CLASSES), 3)) # 加载训练好的Caffe模型
# OpenCV的dnn方法中,可以加载由Caffe,TensorFLow,Darknet,Torch训练得到的模型文件的方法
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"]) # 加载测试图片,并转换成blob(OpenCV需要这样做)
image = cv2.imread(args["image"])
(h, w) = image.shape[:2]
# cv2.dnn.blobFromImage返回一个四维的blob
# 可以对image执行缩放,剪切,交换RB通道,减均值操作
blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 0.007843, (300, 300), 127.5) # 输入到网络中,执行Inference
print("[INFO] computing object detections...")
net.setInput(blob)
start = time.time()
detections = net.forward()
end = time.time()
print("[INFO] SSD took {:6} seconds.".format(end - start))
# pdb.set_trace() for i in range(detections.shape[2]):
# 类别概率
confidence = detections[0, 0, i, 2] # 过滤掉confidence小于人为设定的阈值的detection
if confidence > args["confidence"]:
idx = int(detections[0, 0, i, 1]) # 类别索引
box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
(startX, startY, endX, endY) = box.astype("int") # SSD的输出直接就是框的左上角和右下角的点的坐标位置 # 在图片展示检测的object
label = "{}: {:.2f}%".format(CLASSES[idx], confidence*100)
print("[INFO] {}".format(label))
cv2.rectangle(image, (startX, startY), (endX, endY), COLORS[idx], 2)
y = startY -15 if startY - 15 > 15 else startY + 15
cv2.putText(image, label, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLORS[idx], 2) # 显示
cv2.imshow("Object Detection", image)
cv2.waitKey(0)
cv2.imwrite("lab_2_ssd.jpg", image)

 这样有没有用?????用处不大

  还是需要看论文的。。。。。

Object detection with deep learning and OpenCV的更多相关文章

  1. 论文阅读之: Hierarchical Object Detection with Deep Reinforcement Learning

    Hierarchical Object Detection with Deep Reinforcement Learning NIPS 2016 WorkShop  Paper : https://a ...

  2. paper 159:文章解读:From Facial Parts Responses to Face Detection: A Deep Learning Approach--2015ICCV

    文章链接:https://arxiv.org/pdf/1509.06451.pdf 1.关于人脸检测的一些小小总结(Face Detection by Literature) (1)Multi-vie ...

  3. 论文笔记之:From Facial Parts Responses to Face Detection: A Deep Learning Approach

    From Facial Parts Responses to Face Detection: A Deep Learning Approach ICCV 2015 从以上两张图就可以感受到本文所提方法 ...

  4. 目标检测--Scalable Object Detection using Deep Neural Networks(CVPR 2014)

    Scalable Object Detection using Deep Neural Networks 作者: Dumitru Erhan, Christian Szegedy, Alexander ...

  5. 课程四(Convolutional Neural Networks),第三 周(Object detection) —— 0.Learning Goals

    Learning Goals: Understand the challenges of Object Localization, Object Detection and Landmark Find ...

  6. Scalable Object Detection using Deep Neural Networks译文

    原文:https://arxiv.org/abs/1312.2249

  7. 论文学习-深度学习目标检测2014至201901综述-Deep Learning for Generic Object Detection A Survey

    目录 写在前面 目标检测任务与挑战 目标检测方法汇总 基础子问题 基于DCNN的特征表示 主干网络(network backbone) Methods For Improving Object Rep ...

  8. YOLO object detection with OpenCV

    Click here to download the source code to this post. In this tutorial, you’ll learn how to use the Y ...

  9. deep learning 的综述

    从13年11月初开始接触DL,奈何boss忙or 各种问题,对DL理解没有CSDN大神 比如 zouxy09等 深刻,主要是自己觉得没啥进展,感觉荒废时日(丢脸啊,这么久....)开始开文,即为记录自 ...

随机推荐

  1. Azure CLI的版本问题

    Azure支持多种管理方法.命令行方法有: PowerShell,PowerShell只能运行在Windows上 Azure CLI,而Azure CLI可以运行在Windows.MAC以及Linux ...

  2. 经典SQL问题: 行转列,列转行

    情景简介 学校里面记录成绩,每个人的选课不一样,而且以后会添加课程,所以不需要把所有课程当作列.数据库grade里面数据如下图,假定每个人姓名都不一样,作为主键.本文以MySQL为基础,其他数据库会有 ...

  3. Dubbo各种协议详解

    (1)协议支持 Dubbo支持多种协议,如下所示: Dubbo协议 Hessian协议 HTTP协议 RMI协议 WebService协议 Thrift协议 Memcached协议 Redis协议 在 ...

  4. 我的第一个Socket程序-SuperSocket使用入门(一)

    第一次使用Socket,遇到过坑,也涨过姿势,网上关于SuperSocket的教程基本都停留在官方给的简单demo上,实际使用还是会碰到一些问题,所以准备写两篇博客,分别来介绍SuperSocket以 ...

  5. Synchronized关键字、Lock,并解释它们之间的区别

    Synchronized 与Lock都是可重入锁,同一个线程再次进入同步代码的时候.可以使用自己已经获取到的锁. Synchronized是悲观锁机制,独占锁.而Locks.ReentrantLock ...

  6. 如何使用google等一系列搜索引擎?

    对于我们经常使用的搜索引擎大家都都不陌生,但是,如何高效的利用呢?大家都知道空格是搜索多个关键词,那么有没有其他的快捷键呢?答案是肯定的,以下内容转自知乎 1.双引号 把搜索词放在双引号中,代表完全匹 ...

  7. 2-3 zookeeper文件夹主要目录介绍

    zookeeper-3.4.11.jar.zookeeper-3.4.11.jar.md5.zookeeper-3.4.11.sha1都是通过打包或者编译之后产生的相关的文件.那么maven相关的东西 ...

  8. 在Linux里安装jdk

    一.系统环境说明: [操作系统]:Ubuntu 18.04.1 Desktop [JDK]:jdk1.8.0_181,文件名称:jdk-8u181-linux-x64.tar 二.准备jdk文件 下载 ...

  9. 在Oracle 12C中使用scott账号

    在Oracle11g中默认是有scott账号的,但在Oracle 12C中则不能直接使用. 我的机器环境: 操作系统:Windows Server 2008 R2 64位 Oracle版本:Oracl ...

  10. Boost 线程学习笔记

    Bolg转载自:http://www.cnblogs.com/lvdongjie/p/4447193.html 一: 创建线程 #include <iostream> #include & ...