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
OpenCV install opencv_contrib on Windows
提问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.0、Python 2.7.11和Windows 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
,出现错误。
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:
要遵循的步骤是:
- Install Visual Studio 2013
- Install CMake
- Download both opencv and opencv_contrib from github
- Create a directory
opencv-3.1.0-dev
and in this directory create other two directories one calledbuild
and the other calledsources
. Thepaths
will beopencv-3.1.0-dev\build
andopencv-3.1.0-dev\sources
. - Unzip
opencv-master.zip
andopencv_contrib-master.zip
- In the sources directory created in step 4, paste
opencv
andopencv_contrib
directories - Open CMake and provide two paths, one for the build directory and the other for the sources directory
- 安装 Visual Studio 2013
- 安装CMake
- 从github下载opencv和opencv_contrib
- 创建一个目录,
opencv-3.1.0-dev
并在此目录中创建另外两个目录,一个build
名为sources
. 该paths
会opencv-3.1.0-dev\build
和opencv-3.1.0-dev\sources
。 - 解压
opencv-master.zip
并opencv_contrib-master.zip
- 在步骤 4 中创建的源目录中,粘贴
opencv
和opencv_contrib
目录 - 打开CMake并提供两个路径,一个是build目录,另一个是sources目录
- Press configure, a lot of lines highlighted in red will appear.
- 按configure,会出现很多以红色突出显示的行。
- 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)
- 在这些行出现之前,您必须指定您的编译器。(还可以根据您的需要选择正确的位版本,相同的程序适用于 32 位和 64 位)
- Choose whatever you want to build, but the most important thing to do is to provide the path of the non-free modules.
- 选择你想要构建的任何东西,但最重要的是提供非自由模块的路径。
- Press configureagain and new lines will be highlighted in red.
- Make sure to uncheck BUILD_opencv_contrib_world before pressing generate.
- 再次按配置,新行将以红色突出显示。
- 确保在按下生成之前取消选中 BUILD_opencv_contrib_world。
- The last step with CMake is to press generate.
- Make sure
generating is done
before continuing.
- CMake 的最后一步是按generate。
generating is done
在继续之前确保。
- 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.
- 打开空的构建,你会发现一堆文件。最重要的文件是
OpenCV.sln
. 右键单击此 .sln 文件并使用 CMake 中使用的 Visual Studio 2013 打开它。
Be patient as this step and the next will take a lot of time.
请耐心等待,因为这一步和下一步将花费很多时间。
- Build the 3 files with the order in the following image. Change the mode into
Release
. These step take about 10 to 15 minutes.
- 按照下图中的顺序构建 3 个文件。将模式更改为
Release
. 这些步骤大约需要 10 到 15 分钟。
- Copy all the
.dll
files [present atopencv-3.1.0-dev\build\bin\Release
] and thecv2.pyd
and paste them in thesite-packages
directory inPyhton27\Lib\site-packages
. - To verify the build open Python and execute
import cv2
. If no errors, executecv2.__version__
, and you should get3.1.0-dev
.
- 复制所有
.dll
文件[出席opencv-3.1.0-dev\build\bin\Release
]和cv2.pyd
并将其粘贴在site-packages
目录中Pyhton27\Lib\site-packages
。 - 要验证构建,请打开 Python 并执行
import cv2
. 如果没有错误,执行cv2.__version__
,你应该得到3.1.0-dev
.
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-python
module:
对于 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-python
module.
不要混用 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,其他版本不起作用。