OpenCV-Python官方文档中文翻译2:Install OpenCV-Python in Windows在Windows安装OpenCV-Python

Install OpenCV-Python in Windows

Goals

In this tutorial

  • We will learn to setup OpenCV-Python in your Windows system.

Below steps are tested in a Windows 7-64 bit machine with Visual Studio 2010 and Visual Studio 2012. The screenshots shows VS2012.

在这个教程

  • 我们将学习如何在Windows系统安装OpenCV-Python。

以下步骤是在装有Visual Studio 2010 和 Visual Studio 2012的Windows 7-64bit版本电脑上测试的。截图展示的VS2012版本。

Installing OpenCV from prebuilt binaries从预编译的二进制文件安装OpenCV

  1. Below Python packages are to be downloaded and installed to their default locations.

    1. Python 3.x (3.4+) or Python 2.7.x from here.
    2. Numpy package (for example, using pip install numpy command).
    3. Matplotlib (pip install matplotlib) (Matplotlib is optional, but recommended since we use it a lot in our tutorials).
  2. Install all packages into their default locations. Python will be installed to C:/Python27/ in case of Python 2.7.

  3. After installation, open Python IDLE. Enter import numpy and make sure Numpy is working fine.

  4. Download latest OpenCV release from GitHub or SourceForge site and double-click to extract it.

  5. Goto opencv/build/python/2.7 folder.

  6. Copy cv2.pyd to C:/Python27/lib/site-packages.

  7. Open Python IDLE and type following codes in Python terminal.

    >>> import cv2 as cv

    >>> print( cv.version )

If the results are printed out without any errors, congratulations !!! You have installed OpenCV-Python successfully.

1.下面Python包将被下载和安装到它们的默认位置。

  1. Python 3.x (3.4+) 或者 Python 2.7.x 点击这里下载.
  2. Numpy 包 (例如, 用 pip install numpy 指令下载).
  3. Matplotlib (pip install matplotlib) (*Matplotlib是可选的, 但是建议下载,因为在我们的教程中会大量用到).

2.将所有包安装到默认位置。如果是Python2.7,Python将安装到 C:/Python27/目录。

3.安装后,打开Python集成开发环境。输入 import numpy 并保证Numpy正常工作。

4.从 GitHub 或者 SourceForge site 下载最新发布的OpenCV。双击解压。

5.转到opencv/build/python/2.7文件夹。

6.复制cv2.pydC:/Python27/lib/site-packages

7.打开Python集成开发环境,并在Python终端输入以下代码。

>>> import cv2 as cv

>>> print( cv.version )

如果打印结果显示没有任何错误,恭喜!你已经成功安装OpenCV。

Building OpenCV from source从源代码构建OpenCV

  1. Download and install Visual Studio and CMake.//下载和安装Visual Studio 和 CMake。

    1. Visual Studio 2012
    2. CMake
  2. Download and install necessary Python packages to their default locations//下载和安装必须的Python包到它们默认的位置。

    1. Python
    2. Numpy
    • Note

      In this case, we are using 32-bit binaries of Python packages. But if you want to use OpenCV for x64, 64-bit binaries of Python packages are to be installed. Problem is that, there is no official 64-bit binaries of Numpy. You have to build it on your own. For that, you have to use the same compiler used to build Python. When you start Python IDLE, it shows the compiler details. You can get more information here. So your system must have the same Visual Studio version and build Numpy from source.//在这种情况下,我们使用的是32位进制的Python安装包二进制文件。但如果你想将OpenCV用于x64,需要安装64位进制的Python安装包文件。但问题出在这儿,没有官方的Nmupy库的64位二进制文件。你必须自行构建。为此,你必须使用与构建Python相同的编译器。当你打开Python的集成开发环境,将展示编译器的细节。你可以点击这里获得更多信息。所以,你的系统必须有相同的VS版本并且从源文件构建Numpy。

      Another method to have 64-bit Python packages is to use ready-made Python distributions from third-parties like Anaconda, Enthought etc. It will be bigger in size, but will have everything you need. Everything in a single shell. You can also download 32-bit versions also.//另一种拥有64位Python包的方法是使用现成的第三方Python发行版如Anaconda, Enthought 等等。它在体积上会更大,但是将拥有你所需要的一切。所有都包含在一个单独的壳里。你也能下载32位的版本。

  3. Make sure Python and Numpy are working fine.//确保Python和Numpy正常运行。

  4. Download OpenCV source. It can be from Sourceforge (for official release version) or from Github (for latest source).//下载OpenCV源文件。可以从Sourceforge (官方发布版本) 或者Github (最新版本)下载。

  5. Extract it to a folder, opencv and create a new folder build in it.//解压到一个文件夹,opencv并在其中新建一个文件夹。

  6. Open CMake-gui (Start > All Programs > CMake-gui)//打开 CMake-gui (Start > All Programs > CMake-gui)

  7. Fill the fields as follows (see the image below)😕/如下填充字段(请看下面图片)

    1. Click on Browse Source… and locate the opencv folder.//点击 Browse Source… 并找到opencv文件夹。

    2. Click on Browse Build… and locate the build folder we created.//点击 Browse Build… 并找到我们建立的文件夹。

    3. Click on Configure.//点击Configure

      在这里插入图片描述

    4. It will open a new window to select the compiler. Choose appropriate compiler (here, Visual Studio 11) and click Finish.//将打开一个新的窗口来选择编译器。选择合适的编译器(在这,VS11)并点击完成。

    在这里插入图片描述

    1. Wait until analysis is finished.//等待分析完成。
  8. You will see all the fields are marked in red. Click on the WITH field to expand it. It decides what extra features you need. So mark appropriate fields. See the below image://你将看见所有的字段都被标记为红色。点击WITH字段来展开它。这决定了你所需要的额外的功能。所以,标记合适的字段。请见下图:

在这里插入图片描述

  1. Now click on BUILD field to expand it. First few fields configure the build method. See the below image://现在点击 BUILD字段来展开它。前几个字段配置构建方式。请见下图:

在这里插入图片描述

  1. Remaining fields specify what modules are to be built. Since GPU modules are not yet supported by OpenCV-Python, you can completely avoid it to save time (But if you work with them, keep it there). See the image below://剩余的字段阐明了构建什么模块。既然GPU模块现在并不被OpenCV支持,你可以节约时间不选他。(但如果你想用,就选上)。请见下图:

    在这里插入图片描述

  2. Now click on ENABLE field to expand it. Make sure ENABLE_SOLUTION_FOLDERS is unchecked (Solution folders are not supported by Visual Studio Express edition). See the image below://现在点击ENABLE字段展开它。保证 ENABLE_SOLUTION_FOLDERS模块没被选中( Visual Studio Express版本不支持 解决文件夹 )。请见下图。

在这里插入图片描述

  1. Also make sure that in the PYTHON field, everything is filled. (Ignore PYTHON_DEBUG_LIBRARY). See image below://也确保PYTHON字段,所有的都选中。(忽略 PYTHON_DEBUG_LIBRARY) 。请见下图:

在这里插入图片描述

  1. Finally click the Generate button.//最后点击Generate按钮。

  2. Now go to our opencv/build folder. There you will find OpenCV.sln file. Open it with Visual Studio.//现在去 opencv/build文件夹。找到OpenCV.sln文件。用VS打开。

  3. Check build mode as Release instead of Debug.//检查构建模式,是Release而不是Debug

  4. In the solution explorer, right-click on the Solution (or ALL_BUILD) and build it. It will take some time to finish.//在解决方案管理器中,右键点击Solution(或者ALL_BUILD)构件它。这将花点时间完成。

  5. Again, right-click on INSTALL and build it. Now OpenCV-Python will be installed.//再次,右键点击INSTALL来构建。现在OpenCV-Python将被安装。

    在这里插入图片描述

  6. Open Python IDLE and enter ‘import cv2 as cv’. If no error, it is installed correctly.//打开Python集成开发环境,输入“import cv2 as cv”。如果不报错,那就是正确安装了。

  • Note

    We have installed with no other support like TBB, Eigen, Qt, Documentation etc. It would be difficult to explain it here. A more detailed video will be added soon or you can just hack around.//我们没有安装其他支持像TBB,Eigen,Qt,Documentation等等。在这里很难解释清楚为什么。不久将会添加一个更多细节的视频,或者你可以自己随便看看随便改改。

Additional Resources

Exercises

If you have a windows machine, compile the OpenCV from source. Do all kinds of hacks. If you meet any problem, visit OpenCV forum and explain your problem.//如果你有一台windows计算机,从源代码编译OpenCV。完成各种极客操作。如果遇见任何问题,访问OpenCV论坛,解释你的问题。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值