opencv-machine-learning

授权协议 MIT License
开发语言 Python
所属分类 神经网络/人工智能、 机器学习/深度学习
软件类型 开源软件
地区 不详
投 递 者 闽涵蓄
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Machine Learning for OpenCV

This is the Jupyter notebook version of the following book:


Michael Beyeler
Machine Learning for OpenCV
Intelligent Image Processing with Python

14 July 2017
Packt Publishing Ltd., London, England
Paperback: 382 pages
ISBN 978-178398028-4

The content is available on GitHub.The code is released under the MIT license.

The book is also available as a two-part video course:

For questions, discussions, and more detailed help please refer to the Google group.

If you use either book or code in a scholarly publication, please cite as:

M. Beyeler, (2017). Machine Learning for OpenCV. Packt Publishing Ltd., London, England, 380 pages, ISBN 978-178398028-4.

Or use the following bibtex:

@book{MachineLearningOpenCV,
	title = {{Machine Learning for OpenCV}},
	subtitle = {{Intelligent image processing with Python}},
	author = {Michael Beyeler},
	year = {2017},
	pages = {380},
	publisher = {Packt Publishing Ltd.},
	isbn = {978-178398028-4}
}

Scholarly work referencing this book:

  • S Lynch (2018). Image Processing with Python. Dynamical Systems with Applications using Python, Springer.
  • MQG Quiroz (2018). Inductive Machine Learning with Image Processing for Objects Detection of a Robotic Arm with Raspberry PI. International Conference on Technology Trends.
  • A Konate (2018). Un aperçu sur quelques méthodes en apprentissage automatique supervisé. HAL 01946237.

Table of Contents

Preface

Foreword by Ariel Rokem

  1. A Taste of Machine Learning

  2. Working with Data in OpenCV

  3. First Steps in Supervised Learning

  4. Representing Data and Engineering Features

  5. Using Decision Trees to Make a Medical Diagnosis

  6. Detecting Pedestrians with Support Vector Machines

  7. Implementing a Spam Filter with Bayesian Learning

  8. Discovering Hidden Structures with Unsupervised Learning

  9. Using Deep Learning to Classify Handwritten Digits

  10. Combining Different Algorithms Into an Ensemble

  11. Selecting the Right Model with Hyper-Parameter Tuning

  12. Wrapping Up

Running the Code

There are at least two ways you can run the code:

  • Using Binder (no installation required).
  • Using Jupyter Notebook on your local machine.

The code in this book was tested with Python 3.5, although Python 3.6 and 2.7 should work as well.

Using Binder

Binder allows you to run Jupyter notebooks in an interactive Docker container.No installation required!

Launch the project: mbeyeler/opencv-machine-learning

Using Jupyter Notebook

You basically want to follow the installation instructions in Chapter 1 of the book.

In short:

  1. Download and install Python Anaconda.On Unix, when asked if the Anaconda path should be added to your PATH variable, choose yes. Then either open a new terminal or run $ source ~/.bashrc.

  2. Fork and clone the GitHub repo:

    • Click theForkbutton in the top-right corner of this page.
    • Clone the repo, where YourUsername is your actual GitHub user name:
    $ git clone https://github.com/YourUsername/opencv-machine-learning
    $ cd opencv-machine-learning
    
    • Add the following to your remotes:
    $ git remote add upstream https://github.com/mbeyeler/opencv-machine-learning
    
  3. Add Conda-Forge to your trusted channels (to simplify installation of OpenCV on Windows platforms):

    $ conda config --add channels conda-forge
    
  4. Create a conda environment for Python 3 with all required packages:

    $ conda create -n Python3 python=3.6 --file requirements.txt
    
  5. Activate the conda environment.On Linux / Mac OS X:

    $ source activate Python3
    

    On Windows:

    $ activate Python3
    

    You can learn more about conda environments in theManaging Environmentssection of the conda documentation.

  6. Launch Jupyter notebook:

    $ jupyter notebook
    

    This will open up a browser window in your current directory.Navigate to the folder opencv-machine-learning.The README file has a table of contents.Else navigate to the notebooks folder, click on the notebook of your choice,and select Kernel > Restart & Run All from the top menu.

Getting the latest code

If you followed the instructions above and:

  • forked the repo,
  • cloned the repo,
  • added the upstream remote repository,

then you can always grab the latest changes by running a git pull:

$ cd opencv-machine-learning
$ git pull upstream master

Errata

The following errata have been reported that apply to the print version of the book. Some of these are typos, others are bugs in the code. Please note that all known bugs have been fixed in the code of this repository.

  • p.32: Out[15] should read '3' instead of 'int_arr[3]'.
  • p.32: Out[22] should read array([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]) instead of array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]).
  • p.33: In the sentence: "Here, the first dimension defines the color channel...", the order of color channels should read "blue, green, and red in OpenCV" instead of "red, green, blue, green, and red".
  • p.36: The range of x values should read "0 <= x <= 10" instead of "0 <= x < 10", since np.linspace by default includes the endpoint.
  • p.51: In [15] shoud read precision = true_positive / (true_positive + false_positive) instead of precision = true_positive / (true_positive + true_negative).
  • p.51: Out[15] should read 0.2 instead of 1.0.
  • p.72: In [6] should read ridgereg = linear_model.Ridge() instead of ridgereg = linear_model.RidgeRegression().
  • p.85: The first line of In [8] should read min_max_scaler = preprocessing.MinMaxScaler(feature_range=(-10,10)) instead of min_max_scaler = preprocessing.MinMaxScaler(feature_range (-10,10)).
  • p.91: The last paragraph should read We also specify an empty array, np.array([]), for the mean argument, which tells OpenCV to compute the mean from the data: instead of We also specify an empty array, np.array([]), for the mask argument, which tells OpenCV to use all data points in the feature matrix:.
  • p.112: In [3] should read vec.get_feature_names()[:5] instead of function:vec.get_feature_names()[:5].
  • p.120: In [16] should read dtree = cv2.ml.DTrees_create() instead of dtree = cv2.ml.dtree_create().
  • p.122: In [26] should read with open("tree.dot", 'w'): f = tree.export_graphviz(dtc, out_file=f, feature_names=vec.get_feature_names(), class_names=['A', 'B', 'C', 'D']) instead of with open("tree.dot", 'w'): f = tree.export_graphviz(clf, out_file=f). Also, the second line should be indented.
  • p.147: The first occurrences of X_hypo = np.c_[xx.ravel().astype(np.float32), yy.ravel().astype(np.float32)] and _, zz = svm.predict(X_hypo) should be removed, as they mistakenly appear twice.
  • p.193: In [28] is missing from sklearn import metrics.
  • p.197: The sentence right below In [3] should read "Then we can pass the preceding data matrix (X) to cv2.kmeans", not cv2.means.
  • p.201: Indentation in bullet points 2-4 are wrong. Please refer to the Jupyter notebook for the correct indentation.
  • p.228: The last sentence in the middle paragraph should read "[...] thus hopefully classifying the sample as y_{hat}=+1" instead of "[...] thus hopefully classifying the sample as y_{hat}=-1".
  • p.230: In [2] has wrong indentation: class Perceptron(object) correctly has indentation level 1, but def __init__ should have indentation level 2, and the two commands self.lr = lr; self.n_iter = n_iter should have indentation level 3.
  • p.260: In [5] should read from keras.models import Sequential instead of from keras.model import Sequential.
  • p.260: In [6] should read model.add(Conv2D(n_filters, (kernel_size[0], kernel_size[1]), padding='valid', input_shape=input_shape)) instead of model.add(Convolution2D(n_filters, kernel_size[0], kernel_size[1], border_mode='valid', input_shape=input_shape)).
  • p.260: In [8] should read model.add(Conv2D(n_filters, (kernel_size[0], kernel_size[1]))) instead of model.add(Convolution2D(n_filters, (kernel_size[0], kernel_size[1]))).
  • p.261: In [12] should read model.fit(X_train, Y_train, batch_size=128, epochs=12, verbose=1, validation_data=(X_test, Y_test)) instead of model.fit(X_train, Y_train, batch_size=128, nb_epoch=12, verbose=1, validation_data=(X_test, Y_test)).
  • p.275, in bullet point 2 it should say ret = classifier.predict(X_hypo) instead of zz = classifier.predict(X_hypo); zz = zz.reshape(xx.shape).
  • p.285: plt.imshow(X[i, :].reshape((64, 64)), cmap='gray') should be indented so that it is aligned with the previous line.
  • p.288: In [14] should read _, y_hat = rtree.predict(X_test) instead of _, y_hat = tree.predict(X_test).
  • p.305: The first paragraph should read "...and the remaining folds (1, 2, and 4) for training" instead of "...and the remaining folds (1, 2, and 4) for testing".
  • p.306: In [2] should read from sklearn.model_selection import train_test_split instead of from sklearn.model_selection import model_selection.
  • p.310: In [18] should read knn.train(X_boot, cv2.ml.ROW_SAMPLE, y_boot) instead of knn.train(X_train, cv2.ml.ROW_SAMPLE, y_boot).
  • p.311: In [20] should have a line model.train(X_boot, cv2.ml.ROW_SAMPLE, y_boot) instead of knn.train(X_boot, cv2.ml.ROW_SAMPLE, y_boot), as well as _, y_hat = model.predict(X_oob) instead of _, y_hat = knn.predict(X_oob).
  • p.328: In [5] is missing the statement from sklearn.preprocessing import MinMaxScaler.
  • p.328: In [5] should have a line pipe = Pipeline([("scaler", MinMaxScaler()), ("svm", SVC())]) instead of pipe = Pipeline(["scaler", MinMaxScaler(), ("svm", SVC())]).

Acknowledgment

This book was inspired in many ways by the following authors and their corresponding publications:

These books all come with their own open-source code - check them out when you get a chance!

  • High GUI定义 与操作系统,文件系统和摄像机之类的硬件进行交互的一些函数 High GUI组成 · 硬件相关部分  摄像机的操作 · 文件相关部分  载入和保存图像文件 · 图形用户界面部分  窗口系统,加入鼠标,键盘响应,滑动条 窗口   创建窗口: int cvNamedWindow(char* name, int flags); flags = 1 不能随意调整窗口大小, falgs 

  • 原文来自http://blog.csdn.net/yangtrees/article/details/7447206   一、SVM OpenCV开发SVM算法是基于LibSVM软件包开发的,LibSVM是台湾大学林智仁(Lin Chih-Jen)等开发设计的一个简单、易于使用和快速有效的SVM模式识别与回归的软件包。用OpenCV使用SVM算法的大概流程是 1)设置训练样本集 需要两组数据,一组

  • K近邻算法(K-Nearest Neighbors,KNN)是一种非常简单的机器学习方法,既可以处理分类问题,也可以处理回归问题,而且它的执行效果非常好。 KNN是一种懒惰学习方法(lazy learning algorithm)。所谓懒惰学习算法,指的是直到有了新的测试样本,该算法才开始依据训练样本进行样本的预测处理工作。也就是说,该算法事先不会对训练样本进行任何处理,智慧“懒散"地等待测试样本

  • 由于要做人脸识别的任务,装好TensorFlow之后,打算一鼓作气再把opencv安装好! Let’s go! 经过一番尝试成功了! 首先要说的是,用conda来安装的方法尝试了好几次,都因为网络问题断了,即使已经换了镜像源== conda install -c https://conda.binstar.org/menpo opencv 又由于要用python接口,所以c++版本也不可行 最后,

  • K-Nearest Neighbors 该算法存储所有的训练样本(已知标签),然后通过分析新给的样本(标签未知)与已知标签的训练样本的相似度,选出其中的K个最相似的训练样本进行投票得到新样本的标签,并计算加权和等。 该方法有时被称为是“learning by example”,因为他总是根据新样本的特征向量与已知标签的样本特征向量的相似度来判断新样本的类别。 CvKNearest class  C

  • #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/ml/ml.hpp> #define NTRAINING_SAMPLES100 // Number of training samples per class

  • http://opencv.willowgarage.com/documentation/cpp/ml._machine_learning.html  K Nearest Neighbors Support Vector Machines Decision Trees Boosting Random Trees Expectation-Maximization Neural Networks 

  • 图像通道 单通道:灰度图,黑白图 三通道:彩色图 四通道:彩色图 +透明程度 matx.h 是opencv中的一个基础类 所有对图像的操作归根到底都是对矩阵的操作 介绍 1.头文件 #include "opencv2/core/cvdef.h" #include "opencv2/core/base.hpp" #include "opencv2/core/traits.hpp" 2.矩阵操作定义

  • OpenCV目前在图像处理和识别领域里, 是最强大的开源类库. (maybe我是井底之蛙, 大家有好东西别藏着掖着), 传送门在这: http://opencv.org OpenCV在图像处理和识别领域覆盖的面也非常广泛, 图像的各种操作(缩放, 旋转, 变灰, ColorSpace转换, 门槛值等等等等; 最大的亮点是它实现了非常多的图像抓取和识别算法, 如GrabCut, SIFT, SURF

 相关资料
  • 学习意味着通过学习或经验获得知识或技能。 基于此,我们可以定义机器学习(ML)如下 - 它可以被定义为计算机科学领域,更具体地说是人工智能的应用,其为计算机系统提供了学习数据和从经验改进而无需明确编程的能力。 基本上,机器学习的主要焦点是允许计算机自动学习而无需人为干预。 现在问题是如何开始和完成这种学习? 它可以从数据的观察开始。 数据可以是一些示例,指令或一些直接经验。 然后在此输入的基础上,

  • Machine Learning This project provides a web-interface,as well as a programmatic-apifor various machine learning algorithms. Supported algorithms: Support Vector Machine (SVM) Support Vector Regressio

  • machine – 与硬件相关的功能 machine 模块包含与特定开发板上的硬件相关的特定函数。 在这个模块中的大多数功能允许实现直接和不受限制地访问和控制系统上的硬件块(如CPU,定时器,总线等)。如果使用不当,会导致故障,死机,崩溃,在极端的情况下,硬件会损坏。 需要注意的是,由于不同开发板的硬件资源不同,MicroPython 移植所能控制的硬件也是不一样的。因此对于控制硬件的例程来说,在

  • Machine Learning Projects This repository contains mini projects in machine learning with jupyter notebook files.Go to the projects folder and see the readme for detailed instructions about the projec

  • Machine Learning and Data Science Applications in Industry Sov.ai Research Lab (Sponsorship) Animated Investment Management Research at Sov.ai — Sponsoring open source AI, Machine learning, and Data S

  • Homemade Machine Learning You might be interested in �� Interactive Machine Learning Experiments For Octave/MatLab version of this repository please check machine-learning-octave project. This reposit