OpenCV在Windows上安装opencv_contrib [英] OpenCV install opencv_contrib on Windows
问题描述
我正在使用 OpenCV 3.1.0 , Python 2.7.11 和 Windows 10.我想构建额外的模块( opencv_contrib ).
I am using OpenCV 3.1.0 , Python 2.7.11 and Windows 10. I want to build the extra modules (opencv_contrib) into OpenCV.
我遵循此 GitHub 中的步骤.
$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5
当我键入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.
推荐答案
更新29-5-2017:这也适用于OpenCV 3.2.0-dev.现在使用Visual Studio 2015或2017没有错误.
Update 29-5-2017: This also works with OpenCV 3.2.0-dev. Now using Visual Studio 2015 or 2017 gives no errors.
cv2.pyd现在自动移至站点程序包.您只需要复制DLL.
我做了一个有关如何从头开始编译和构建自己的OpenCV 3.1.0-dev的教程.它简单而有条理,与我合作非常好.如果您有时间重新编译OpenCV,请查看教程.
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.
要执行的步骤是:
- 安装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中创建的sources目录中,粘贴
opencv
和opencv_contrib
目录 - 打开CMake并提供两条路径,一条用于构建目录,另一条用于源目录
- 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
- 按 configure (配置),将显示很多以红色突出显示的行.
- Press configure, a lot of lines highlighted in red will appear.
- 在出现这些行之前,您必须指定编译器. (还可以根据您的需要选择正确的位版本,相同的步骤适用于32-bt和64-bit)
- 选择任何您想构建的东西,但是最重要的是提供非自由模块的路径.
-
再次
- 按配置,新行将以红色突出显示.
- 在按生成"之前,请确保取消选中BUILD_opencv_contrib_world.
- Press configure again and new lines will be highlighted in red.
- Make sure to uncheck BUILD_opencv_contrib_world before pressing generate.
- 使用CMake的最后一步是按生成.
- 在继续之前确保
generating is done
.
- The last step with CMake is to press generate.
- Make sure
generating is done
before continuing.
- 打开为空的内部版本,您会发现一堆文件.最重要的文件是
OpenCV.sln
.右键单击此.sln文件,然后使用CMake中使用的Visual Studio 2013将其打开.
- 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.
此步骤要耐心等待,下一步需要很多时间.
- 按照下图的顺序构建3个文件.将模式更改为
Release
.这些步骤大约需要10到15分钟.
- Build the 3 files with the order in the following image. Change the mode into
Release
. These step take about 10 to 15 minutes.
- 复制[在
opencv-3.1.0-dev\build\bin\Release
处的所有.dll
文件"和cv2.pyd
,并将它们粘贴到Pyhton27\Lib\site-packages
的site-packages
目录中. - 要验证构建,请打开Python并执行
import cv2
.如果没有错误,请执行cv2.__version__
,您将得到3.1.0-dev
.
- 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
.
如果不清楚,请观看此答案开头提供的教程.
If anything is not clear please watch the tutorial provided at the beginning of this answer.
这篇关于OpenCV在Windows上安装opencv_contrib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!