Python OpenCV 在 Windows 上安装 opencv_contrib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37517983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:30:08  来源:igfitidea点击:

OpenCV install opencv_contrib on Windows

pythonopencvopencv-contrib

提问by VICTOR

I am using OpenCV 3.1.0, Python 2.7.11and Windows 10.I want to build the extra modules (opencv_contrib) into OpenCV.

我正在使用OpenCV 3.1.0Python 2.7.11Windows 10。我想将额外的模块 ( opencv_contrib)构建到 OpenCV 中。

I follow the step in this GitHub.

我按照此GitHub 中的步骤进行操作。

$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5

When I type cmake _DOPENCV_EXTRA_MODULES_PATH=C:\opencv_contrib\opencv_contrib/modules C:\opencv\sources, there is an error.

当我输入时cmake _DOPENCV_EXTRA_MODULES_PATH=C:\opencv_contrib\opencv_contrib/modules C:\opencv\sources,出现错误

enter image description here

在此处输入图片说明

I am looking for help how can I solve it. Thank you.

我正在寻求帮助,我该如何解决。谢谢你。

回答by Tes3awy

Update 29-5-2017: This also works with OpenCV 3.2.0-dev. Now using Visual Studio 2015 or 2017 gives no errors.

The cv2.pyd is now automatically moved to site-packages. You just only need to copy the DLLs.

2017 年 5 月 29 日更新:这也适用于 OpenCV 3.2.0-dev。现在使用 Visual Studio 2015 或 2017 没有错误

cv2.pyd 现在自动移动到站点包。您只需要复制 DLL。

I have made a tutorial on how to compile and build your own OpenCV 3.1.0-dev from scratch. It is simple and organized and works with me very well. If you have time to recompile OpenCV check out the tutorial.

我已经制作了一个关于如何从头开始编译和构建您自己的 OpenCV 3.1.0-dev 的教程。它简单而有条理,与我合作得很好。如果您有时间重新编译 OpenCV,请查看教程

The steps to follow are:

要遵循的步骤是:

  1. Install Visual Studio 2013
  2. Install CMake
  3. Download both opencv and opencv_contrib from github
  4. Create a directory opencv-3.1.0-devand in this directory create other two directories one called buildand the other called sources. The pathswill be opencv-3.1.0-dev\buildand opencv-3.1.0-dev\sources.
  5. Unzip opencv-master.zipand opencv_contrib-master.zip
  6. In the sources directory created in step 4, paste opencvand opencv_contribdirectories
  7. Open CMake and provide two paths, one for the build directory and the other for the sources directory
  1. 安装 Visual Studio 2013
  2. 安装CMake
  3. github下载opencv和opencv_contrib
  4. 创建一个目录,opencv-3.1.0-dev并在此目录中创建另外两个目录,一个build名为sources. 该pathsopencv-3.1.0-dev\buildopencv-3.1.0-dev\sources
  5. 解压opencv-master.zipopencv_contrib-master.zip
  6. 在步骤 4 中创建的源目录中,粘贴opencvopencv_contrib目录
  7. 打开CMake并提供两个路径,一个是build目录,另一个是sources目录

cmake

制作

  1. Press configure, a lot of lines highlighted in red will appear.
  1. configure,会出现很多以红色突出显示的行。

configure

配置

  1. before these lines appear you will have to specify your compiler. (Also select correct bit version based on your needs, same procedure works for 32-bt and 64-bit)
  1. 在这些行出现之前,您必须指定您的编译器。(还可以根据您的需要选择正确的位版本,相同的程序适用于 32 位和 64 位)

compiler

编译器

  1. Choose whatever you want to build, but the most important thing to do is to provide the path of the non-free modules.
  1. 选择你想要构建的任何东西,但最重要的是提供非自由模块的路径。

extra modules

额外模块

  1. Press configureagain and new lines will be highlighted in red.
  2. Make sure to uncheck BUILD_opencv_contrib_world before pressing generate.
  1. 再次按配置,新行将以红色突出显示。
  2. 确保在按下生成之前取消选中 BUILD_opencv_contrib_world。

new

新的

  1. The last step with CMake is to press generate.
  2. Make sure generating is donebefore continuing.
  1. CMake 的最后一步是按generate
  2. generating is done在继续之前确保。

generating done

生成完成

  1. open the build that was empty and you will find a bunch of files. The most important file is OpenCV.sln. Right click on this .sln file and open it with the visual studio 2013 used in CMake.
  1. 打开空的构建,你会发现一堆文件。最重要的文件是OpenCV.sln. 右键单击此 .sln 文件并使用 CMake 中使用的 Visual Studio 2013 打开它。

the sln file

.sln 文件

Be patient as this step and the next will take a lot of time.

请耐心等待,因为这一步和下一步将花费很多时间。

  1. Build the 3 files with the order in the following image. Change the mode into Release. These step take about 10 to 15 minutes.
  1. 按照下图中的顺序构建 3 个文件。将模式更改为Release. 这些步骤大约需要 10 到 15 分钟。

build

建造

  1. Copy all the .dllfiles [present at opencv-3.1.0-dev\build\bin\Release] and the cv2.pydand paste them in the site-packagesdirectory in Pyhton27\Lib\site-packages.
  2. To verify the build open Python and execute import cv2. If no errors, execute cv2.__version__, and you should get 3.1.0-dev.
  1. 复制所有.dll文件[出席opencv-3.1.0-dev\build\bin\Release]和cv2.pyd并将其粘贴在site-packages目录中Pyhton27\Lib\site-packages
  2. 要验证构建,请打开 Python 并执行import cv2. 如果没有错误,执行cv2.__version__,你应该得到3.1.0-dev.

verification

确认

If anything is not clear please watch the tutorial provided at the beginning of this answer.

如果有任何不清楚的地方,请观看本答案开头提供的教程。

回答by FooBar167

For Python 3.6/3.5 you could use *.whl (Python on Wheels) module from here:

对于 Python 3.6/3.5,您可以从这里使用 *.whl (Python on Wheels) 模块:

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

For Python 2.7 there is no opencv+contrib in one module, but you could separately install opencv module without contrib from here at the end of the pageand then add opencv-contrib-pythonmodule:

对于 Python 2.7,一个模块中没有 opencv+contrib,但您可以从页面末尾的此处单独安装不带 contrib 的 opencv 模块,然后添加opencv-contrib-python模块:

pip install opencv_python-3.2.0.7-cp27-cp27m-win_amd64.whl
pip install opencv-contrib-python

Do not mix opencv+contrib opencv-python (3.2.0+contrib)and opencv-contrib-python (3.2.0.7)modules, otherwise your "import cv2" stop to work till you delete opencv-contrib-pythonmodule.

不要混用 opencv+contribopencv-python (3.2.0+contrib)opencv-contrib-python (3.2.0.7)模块,否则你的“ import cv2”将停止工作,直到你删除opencv-contrib-python模块。

回答by Amber

no need for complex stuff, just uninstall the version of opencv you have and do:

不需要复杂的东西,只需卸载您拥有的 opencv 版本并执行以下操作:

pip install opencv-contrib-python

Good luck, Amber

祝你好运,琥珀

回答by daithuongphu

The answer of foo baris the best simple way to add opencv_contrib to python. But opencv_python-3.2.0.7-cp27-cp27m-win_amd64.whl is just for AMD chips. If you run it on Intel chip you will receive error message like this: "XXX is not a supported wheel on this platform". In this case, you must use opencv_python-3.2.0.7-cp27-cp27m-win32.whl.

foo bar的答案是将 opencv_contrib 添加到 python 的最佳简单方法。但是 opencv_python-3.2.0.7-cp27-cp27m-win_amd64.whl 仅适用于 AMD 芯片。如果您在英特尔芯片上运行它,您将收到如下错误消息:“XXX 不是此平台上支持的轮子”。在这种情况下,您必须使用 opencv_python-3.2.0.7-cp27-cp27m-win32.whl。

回答by tfv

It seems that you have no compiler installed or it is not found.

好像你没有安装编译器或者没有找到。

I have successfully worked with this guide:

我已成功使用本指南:

http://docs.opencv.org/3.0-rc1/d5/de5/tutorial_py_setup_in_windows.html

http://docs.opencv.org/3.0-rc1/d5/de5/tutorial_py_setup_in_windows.html

However, it was necessary to use Visual Studio 12 2013, other versions did not work.

但是,必须使用Visual Studio 12 2013,其他版本不起作用。