OpenCV 3.3 
Aug 3, 2017

OpenCV 3.3 has been released with greatly improved Deep Learning module and lots of optimizations.

Adrian Rosebrock: http://www.pyimagesearch.com/author/adrian/ [nice]

Ref: Real-time object detection with deep learning and OpenCV

Thus, tracking is essential.

Multiple-thread is another consideration: Efficient, threaded video streams with OpenCV

 
 

The following networks have been tested and known to work:

    • AlexNet
    • GoogLeNet v1 (also referred to as Inception-5h)
    • ResNet-34/50/...
    • SqueezeNet v1.1
    • VGG-based FCN (semantical segmentation network)
    • ENet (lightweight semantical segmentation network)
    • VGG-based SSD (object detection network)
    • MobileNet-based SSD (light-weight object detection network)

下面是我们将用到的一些函数。

在dnn中从磁盘加载图片:

    • cv2.dnn.blobFromImage
    • cv2.dnn.blobFromImages

用“create”方法直接从各种框架中导出模型:

    • cv2.dnn.createCaffeImporter
    • cv2.dnn.createTensorFlowImporter
    • cv2.dnn.createTorchImporter

使用“读取”方法从磁盘直接加载序列化模型:

    • cv2.dnn.readNetFromCaffe
    • cv2.dnn.readNetFromTensorFlow
    • cv2.dnn.readNetFromTorch
    • cv2.dnn.readhTorchBlob

从磁盘加载完模型之后,可以用.forward方法来向前传播我们的图像,获取分类结果。

看样子就是好东西,那么,一起来安装:Installing OpenCV 3.3.0 on Ubuntu 16.04 LTS

You may meet the trouble in conflicting with python in anaconda3. Solve it as following:

  1. lolo@lolo-UX303UB$ mv /usr/bin/python3
  2. python3 python3.-config python3.4m-config python3m
  3. python3. python3.4m python3-config python3m-config
  4.  
  5. lolo: Move them away.
  1. cmake -D CMAKE_BUILD_TYPE=RELEASE \
  2. -D CMAKE_INSTALL_PREFIX=/usr/local/anaconda3 \
  3. -D INSTALL_PYTHON_EXAMPLES=ON \
  4. -D INSTALL_C_EXAMPLES=OFF \
  5. -D OPENCV_EXTRA_MODULES_PATH=/home/unsw/Android/opencv-3.3./opencv_contrib-3.3./modules \
  6. -D PYTHON_EXECUTABLE=/usr/local/anaconda3/bin/python3. \
  7. -D BUILD_EXAMPLES=ON ..

Done :-)

Installing ref: 

https://hackmd.io/s/S1gWq7BwW

http://www.linuxfromscratch.org/blfs/view/cvs/general/opencv.html

https://medium.com/@debugvn/installing-opencv-3-3-0-on-ubuntu-16-04-lts-7db376f93961


Now, you have got everything. Let's practice.

From: http://www.pyimagesearch.com/2017/09/11/object-detection-with-deep-learning-and-opencv/

In the first part of today’s post on object detection using deep learning we’ll discuss Single Shot Detectors and MobileNets.

SSD Paper: http://lib.csdn.net/article/deeplearning/53059

SSD Paperhttps://arxiv.org/abs/1512.02325 [Origin]

When it comes to deep learning-based object detection there are three primary object detection methods that you’ll likely encounter:

If we combine both the MobileNet architecture and the Single Shot Detector (SSD) framework, we arrive at a fast, efficient deep learning-based method to object detection.

The model we’ll be using in this blog post is a Caffe versionof the original TensorFlow implementation by Howard et al. and was trained by chuanqi305 (see GitHub).

In this section we will use the MobileNet SSD + deep neural network ( dnn ) module in OpenCV to build our object detector.

Code analysis: 

  1. # USAGE
  2. # python deep_learning_object_detection.py --image images/example_01.jpg \
  3. # --prototxt MobileNetSSD_deploy.prototxt.txt --model MobileNetSSD_deploy.caffemodel
  4.  
  5. # import the necessary packages
  6. import numpy as np
  7. import argparse
  8. import cv2
  9.  
  10. # construct the argument parse and parse the arguments
  11. ap = argparse.ArgumentParser()
  12. ap.add_argument("-i", "--image", required=True,
  13. help="path to input image")
  14. ap.add_argument("-p", "--prototxt", required=True,
  15. help="path to Caffe 'deploy' prototxt file")
  16. ap.add_argument("-m", "--model", required=True,
  17. help="path to Caffe pre-trained model")
  18. ap.add_argument("-c", "--confidence", type=float, default=0.2,
  19. help="minimum probability to filter weak detections")
  20. args = vars(ap.parse_args())
  21.  
  22. # initialize the list of class labels MobileNet SSD was trained to
  23. # detect, then generate a set of bounding box colors for each class
  24. CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat",
  25. "bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
  26. "dog", "horse", "motorbike", "person", "pottedplant", "sheep",
  27. "sofa", "train", "tvmonitor"]
  28. COLORS = np.random.uniform(0, 255, size=(len(CLASSES), 3))
  29.  
  30. # load our serialized model from disk
  31. print("[INFO] loading model...")
  32. net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])
  33.  
  34. # load the input image and construct an input blob for the image
  35. # by resizing to a fixed 300x300 pixels and then normalizing it
  36. # (note: normalization is done via the authors of the MobileNet SSD
  37. # implementation)
  38. image = cv2.imread(args["image"])
  39. (h, w) = image.shape[:2]
  40. blob = cv2.dnn.blobFromImage(image, 0.007843, (300, 300), 127.5)  # --> NCHW
  41.  
  42. # pass the blob through the network and obtain the detections and
  43. # predictions
  44. print("[INFO] computing object detections...")
  45. net.setInput(blob)
  46. detections = net.forward()  # --> net.forward
  47. # loop over the detections
  48. for i in np.arange(0, detections.shape[2]):
  49. # extract the confidence (i.e., probability) associated with the
  50. # prediction
  51. confidence = detections[0, 0, i, 2]
  52.  
  53. # filter out weak detections by ensuring the `confidence` is
  54. # greater than the minimum confidence
  55. if confidence > args["confidence"]:
  56. # extract the index of the class label from the `detections`,
  57. # then compute the (x, y)-coordinates of the bounding box for
  58. # the object
  59. idx = int(detections[0, 0, i, 1])
  60. box= detections[0, 0, i, 3:7] * np.array([w, h, w, h])
  61. (startX, startY, endX, endY) = box.astype("int")
  62.  
  63. # display the prediction
  64. label = "{}: {:.2f}%".format(CLASSES[idx], confidence * 100)
  65. print("[INFO] {}".format(label))
  66. cv2.rectangle(image, (startX, startY), (endX, endY), COLORS[idx], 2)
  67. y = startY - 15 if startY - 15 > 15 else startY + 15
  68. cv2.putText(image, label, (startX, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, COLORS[idx], 2)
  69. # show the output image
  70. cv2.imshow("Output", image)
  71. cv2.waitKey(0)

NCHW

There is a comment that explains this, but in a different source file, ConvolutionalNodes.h, pasted below.

Note that the NVidia abbreviations refer to row-major layout, so to map them to column-major tensor indices are used by CNTK, you will need to reverse their order. E.g. cudnn stores images in “NCHW,” which is a [W x H x C x N] tensor in CNTK notation (W being the fastest-changing dimension; and there are N objects of dimension [W x H x C] concatenated).

Note that the “legacy” (non-cuDNN) memory layout is old code written before NCHW became the standard, so we are likely phasing out the old representation eventually.

net.forward

  1. [INFO] loading model...
  2. [INFO] computing object detections...
  3. (1, 1, 2, 7)
  4. [[[[ 0. 12. 0.95878285 0.49966827 0.6235761 0.69597626 0.87614471]
  5. [ 0. 15. 0.99952459 0.04266162 0.20033446 0.45632178 0.84977102]]]]
  6. [INFO] dog: 95.88%
  7. [INFO] person: 99.95%

[OpenCV] Install OpenCV 3.3 with DNN的更多相关文章

  1. [OpenCV] Install OpenCV 3.4 with DNN

    目标定位 一.开始全面支持 Tensorflow OpenCV3.4 新功能 当前最新进展OpenCV 3.4 dev:https://github.com/opencv/opencv/tree/ma ...

  2. [OpenCV] Install openCV in Qt Creator

    Learn openCV.pdf qmake: link with opencv (Key Point) QT += core gui greaterThan(QT_MAJOR_VERSION, 4) ...

  3. Install OpenCV 3.0 and Python 2.7+ on OSX

    http://www.pyimagesearch.com/2015/06/15/install-OpenCV-3-0-and-Python-2-7-on-osx/ As I mentioned las ...

  4. Install OpenCV 3.0 and Python 2.7+ on Ubuntu

    为了防止原文消失或者被墙,转载留个底,最好还是去看原贴,因为随着版本变化,原贴是有人维护升级的 http://www.pyimagesearch.com/2015/06/22/install-Open ...

  5. $ npm install opencv ? 你试试?! 在windows环境下,使用node.js调用opencv攻略

    博主之前写过一篇文章<html5与EmguCV前后端实现——人脸识别篇>,叙述的是opencv和C#的故事.最近在公司服务器上更新了一套nodejs环境,早就听闻npm上有opencv模块 ...

  6. [OpenCV] How to install opencv by compiling source code

    Introduction Install OpenCV and its dependence ! STEPs 1, compiler sudo apt-get install build-essent ...

  7. Install OpenCV on Ubuntu or Debian

    http://milq.github.io/install-OpenCV-ubuntu-debian/转注:就用第一个方法吧,第二个方法的那个sh文件执行失败,因为我价格kurento.org的源,在 ...

  8. Install opencv on Centos

    研究centos 有很长一段时间了,一直没有写过这方面的感觉,今天在看到网友的一篇文章时,结合亲身体会就下面安装opencv的一些步骤与大家共享. CentOS OpenCV已被广泛应用但是也在不断的 ...

  9. 【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0 +VS 2013 开发环境配置

    图片太多,具体过程参照: [OpenCV入门教程之一] 安装OpenCV:OpenCV 3.0.OpenCV 2.4.8.OpenCV 2.4.9 +VS 开发环境配置 说下我这边的设置: 选择deb ...

随机推荐

  1. Codeforces Round #410 (Div. 2) 题解 【ABCD】

    A 题意:问你恰好修改一个字符,能不能使得字符串变成回文串 题解:显然直接for一遍,如果长度为偶数,那么不一样的必须是1个:如果长度为奇数,那么不一样的也可以是0个 #include<bits ...

  2. Oracle的decode、sign、trunc函数

    原文http://knowyouknowme.iteye.com/blog/574974 一.decode 在Oracle/PLSQL中,  decode 具有和 IF-THEN-ELSE 一样的功能 ...

  3. 在 Python 中使用 in_memory 工作空间

    在 Python 中使用 in_memory 工作空间 在 Python 脚本中,in_memory 工作空间仅对地理处理工具有效:它不是可以写入任何数据的通用虚拟目录. 您可以按以下代码示例所示使用 ...

  4. .Net Standard HttpClient封装Htt请求常用操作整理

    一.常用Http操作 1.Get请求,有参数,无参数 2.Post 请求,有参数,无参数 3.文件简单下载 修改NetHelper中Post请求方法Bug:请求编码默认UTF8,字符串内存流读取后这是 ...

  5. C#利用QRCoder生产二维码

    系统使用.NET4.5.1 代码如下: using System; using System.Collections.Generic; using System.Linq; using System. ...

  6. Morris图表使用小记

    挺好用的,碰到几个问题,有的是瞎试解决了的: 1.我想折线图能够响应单击事件,即点击某个节点后,就能加载进一步的信息,帮助没找到,参照另外一个地方的写法,居然支持事件 Morris.Line({ el ...

  7. ASP.NET Core入门系列教程

    微软把这个新的框架叫:Razor Pages,以下文中我们将频繁提及—Razor Pages. 项目目录结构 wwwroot静态资源文件夹首先,Razor Pages项目中多了一个wwwroot的文件 ...

  8. virt-manager中为centos 7.2 扩容根分区

    1. 打开virt-manager,添加一块磁盘. Add Hardware --> 选中Storage --> Manager (操作参考下图) 点击Manager之后,弹出Choose ...

  9. Spark机器学习(7):KMenas算法

    KMenas算法比较简单,不详细介绍了,直接上代码. import org.apache.log4j.{Level, Logger} import org.apache.spark.{SparkCon ...

  10. Java通过JNI调用C++程序

    JNI是Java Native Interface的缩写,中文为JAVA本地调用.使用JNI可以很方便的用我们的Java程序调用C/C++程序.很多时候,某些功能用Java无法实现,比如说涉及到底层驱 ...