《Machine learning for OpenCV》 Windows下的Anaconda+OpenCV的环境配置

我的电脑是win7,64位的系统,而且之前因为配置caffe下载安装了一些Anaconda Python 2.7版本,OpenCV2.4.13,还有就是OpenCV3.10版本。比较乱比较杂。而《Machine learning for OpenCV》一书中要求的是:
1.带有Python3.5 及以上版本Anaconda
2.OpenCV3.1及以上版本
3.一些支持工具包

所以我把原先的Anaconda卸载了,重新安装了新的版本,而且在Anaconda环境下配置OpenCV也和直接从OpenCV官网下载.exe然后安装不一样,相信也会有读者遇到和我一样的问题。

1、下载开源书籍

首先我们可以从 这里 从Github上下载《Machine learning for OpenCV》这本书籍。
(Tips:因为Windows自带的cmd界面感不是很友好,我们还需要安装Cmder 或者Git bash 命令行工具。)
下载完名为:opencv-machine-learning-master.zip 文件我们解压可以得到以下文件内容。

opencv-machine-learning-master目录下为:
这里写图片描述

notebooks目录下为:
这里写图片描述

可以看见书的内容是ipynb格式的,不是直接电脑编辑软件打开就可以看的格式。

2、安装Anaconda

Anaconda自带了包括Numpy,Scipy,scikit-learn,Matplotlib,Jupter Notebook等工具包,我们可以从Anaconda官网
这里写图片描述

要选择Python3.6版本的,根据电脑情况选择64位还是32位。64位的。(64位的百度云盘链接为:http://pan.baidu.com/s/1mhAU3Pm 密码:z4wx)

下载完.exe文件,正常选择路径然后安装就行了。而安装后需要将两个路径加入到电脑的环境变量中去,此处我安装的路径直接就是G盘,所以要在Path中将:
1、G:\Anaconda
2、G:\Anaconda\Scripts(这个很重要,当时我就是没有添加这个,不能使用conda命令行)
(有时可能需要将电脑重启环境变量才可以生效。)

以上操作完成后,打开我们刚才下载的命令行工具,我用的是Cmder(或者直接cmd也可以)
输入:conda list
若输出为:
这里写图片描述
以上就说明我们Anaconda环境配置成功了。

3、Anaconda环境下配置OpenCV

因为我们上面配置Anaconda环境下的Python是3.6版本的,而正常在官网下载的OpenCV Windows安装包都是这种:

这里写图片描述

若直接在build\python\2.7\x64\cv2.pyd文件复制进Anaconda目录下的Lib\site-packages文件夹中,后续安装过程会有版本不匹配的报错,因为cv2.pyd是使用于Python2.7版本的。
为了方便大家下载:
百度网盘地址:http://pan.baidu.com/s/1dFla7RV
密码:44um
其他版本的下载地址在 这里 大家根据自己Pythond的版本需要选择自己的版本下载即可。
此处我们下载的是名为:opencv_python-3.2.0-cp36-cp36m-win_amd64.whl 的文件,将此文件下载到Anaconda目录下的Lib\site-packages文件夹中,然后在上述路径下打开Cmder(或者是cmd)输入:

pip install opencv_python-3.2.0-cp36-cp36m-win_amd64.whl

然后执行,(安装时忘记截图了)安装成功会有类似于

...
Installing collected packages: opencv-python
Successfully installed opencv-python-3.2.0

的出现。此时可以在Python的编译环境中输入 import cv2 回车 不报错,则配置成功。

然后就是依次输入:

conda config --add channels conda-forge

执行完输入:

conda create -n Python3 python=3.6 --file requirements.txt

因为我们的版本是Python3.6, 而原书是Python3.5,所以这里是 python=3.6。

上面这步是最容易出问题的。

可以看见 requirements.txt 文件的内容是如下,就是一些重要工具包的名称。
这里写图片描述
而在Anaconda\pkgs文件夹下可以看见很多压缩包
这里写图片描述

在这个文件夹中有一个urls.txt的文件,打开以后其实里面就是各个需要安装包的安装地址:

这里写图片描述

以上步骤中如果那个文件下载报错,就可以在这个文件中找到相关的下载地址,手动下载再放到这个文件夹中也可以。

一切准备就绪以后,直接输入activate Python3 就可以最终配置完成了。

4、验证配置

完成上述安装后,在opencv-machine-learning-master\notebooks路径下打开Cmder,在其中输入ipython notebook(或者 jupyter notebook)就可以在网页上打开书籍开始阅读啦。

在第1章和第2章书中只是带我们了解一下Numpy,scikit-learn等工具包的使用,我们可以在Cmder工具下输入ipyhton
这里写图片描述

就可以开始我们的探索之旅啦~

相关内容可以参考我相关的博客,有问题之处欢迎指出,共同交流学习!

Machine learning is no longer just a buzzword, it is all around us: from protecting your email, to automatically tagging friends in pictures, to predicting what movies you like. As a subfield of data science, machine learning enables computers to learn through experience: to make predictions about the future using collected data from the past. And the amount of data to be analyzed is enormous! Current estimates put the daily amount of produced data at 2.5 exabytes (or roughly 1 billion gigabytes). Can you believe it? This would be enough data to fill up 10 million blu-ray discs, or amount to 90 years of HD video. In order to deal with this vast amount of data, companies such as Google, Amazon, Microsoft, and Facebook have been heavily investing in the development of data science platforms that allow us to benefit from machine learning wherever we go—scaling from your mobile phone application all the way to supercomputers connected through the cloud. In other words: this is the time to invest in machine learning. And if it is your wish to become a machine learning practitioner, too—then this book is for you! But fret not: your application does not need to be as large-scale or influential as the above examples in order to benefit from machine learning. Everyone starts small. Thus, the first step of this book is to introduce you to the essential concepts of statistical learning, such as classification and regression, with the help of simple and intuitive examples. If you have already studied machine learning theory in detail, this book will show you how to put your knowledge into practice. Oh, and don't worry if you are completely new to the field of machine learning—all you need is the willingness to learn. Once we have covered all the basic concepts, we will start exploring various algorithms such as decision trees, support vector machines, and Bayesian networks, and learn how to combine them with other OpenCV functionality. Along the way, you will learn how to understand the task by understanding the data and how to build fully functioning machine learning pipelines.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值