一、准备工作
1.安装Anaconda
2.Anaconda Prompt安装opencv
(1)如果系统当中只有一个Python环境,直接输入pip install;
(2)如果有多个Python环境,去指定的位置安装;
进入到Anaconda安装的路径,输入:cd anaconda3
输入dir查看目录,输入python,查看python环境:
(base) C:\Users\16550.000\anaconda3>python
Python 3.7.6 (default, Jan 8 2020, 20:23:39) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type “help”, “copyright”, “credits” or “license” for more information.
退出:exit()
退出后,输入cd Scripts进入到C:\Users\16550.000\anaconda3\Scripts>
Anaconda中的配置工具都在这个文件夹中,比如pip命令
输入pip list查看当前都安装了哪些工具包
接下来进行OpenCV安装,只需要安装Python版本就够了:
输入pip install opencv-python3.4.1.15
(因为opencv3.4.2以后的版本中有些算法被申请了专利,如特征提取,所以这里安装3.4.1版本)
报错:
ERROR: Could not find a version that satisfies the requirement opencv-python3.4.1.15 (from versions: 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20, 3.4.6.27, 3.4.7.28, 3.4.8.29, 3.4.9.31, 3.4.9.33, 3.4.10.35, 4.0.0.21, 4.0.1.23, 4.0.1.24, 4.1.0.25, 4.1.1.26, 4.1.2.30, 4.2.0.32, 4.2.0.34, 4.3.0.36)
ERROR: No matching distribution found for opencv-python3.4.1.15
解决办法1:
重新输入命令:>pip install opencv-python
Collecting opencv-python
Downloading opencv_python-4.3.0.36-cp37-cp37m-win_amd64.whl (33.4 MB)
|████████████████████████████████| 33.4 MB 252 kB/s
Requirement already satisfied: numpy>=1.14.5 in c:\users\16550.000\anaconda3\lib\site-packages (from opencv-python) (1.18.1)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.3.0.36
弊端:安装的不是opencv-python3.4.1.15版本
解决办法2:
opencv-python3.4.1.15需要python3.6版本才能支持,步骤如下:
conda create --name py3.6 python=3.6 #创建python3.6环境
conda activate py3.6 #进入该环境
pip install opencv-python3.4.1.15 #安装opencv
pip install opencv-contrib-python3.4.1.15 #安装opencv的其他包
opencv-python3.4.1.15版本安装成功!
打开Anaconda Navigator,安装 Anaconda Prompt,然后点launch运行
打开窗口后输入python,进入python3.6.10
输入import cv2,没有异常提示
输入cv2.version,显示opencv版本’3.4.1’
成功!
退出exit()
接着安装opencv-contrib-python(3.4.1.15),输入命令:
(py3.6) C:\Users\16550.000>pip install opencv-contrib-python3.4.1.15
显示:
Collecting opencv-contrib-python3.4.1.15
Downloading opencv_contrib_python-3.4.1.15-cp36-cp36m-win_amd64.whl (39.2 MB)
|████████████████████████████████| 39.2 MB 93 kB/s
Requirement already satisfied: numpy>=1.11.3 in c:\users\16550.000\anaconda3\envs\py3.6\lib\site-packages (from opencv-contrib-python==3.4.1.15) (1.19.1)
Installing collected packages: opencv-contrib-python
Successfully installed opencv-contrib-python-3.4.1.15
至此,opencv已经配置好了!!!
3.其他工具包的安装:pip install 工具包的名字,看能否安装成功,如果不能安装,打开windows非官方python工具包安装地址,收录了很多工具包,ctrl+f搜索要安装的工具包,直接将文件复制到Scripts中,网站名称:
Unofficial Windows Binaries for Python Extension Packages
4.代码编写环境:Jupyter Notebook
用Jupyter Notebook可以实现课件与代码结合。
5.项目实战基于eclipse,也可以自己选择,只要可以debug就好,这里选择安装PyCharm。
6.安装步骤:
(1)首先打开浏览器,输入PyCharm点击搜索,点击标题进入网页,点击community下的DAWNLOAD;
(2)当下载好以后,点击安装,记得修改安装路径,我这里放的是D盘,修改好以后,Next
点击install,静静的等待…
(3)接下来的使用和配置,参考网址:https://www.runoob.com/w3cnote/pycharm-windows-install.html