OpenCV 在 Windows 上安装 opencv_contrib [英] OpenCV install opencv_contrib on Windows
问题描述
我正在使用 OpenCV 3.1.0、Python 2.7.11 和 Windows 10.我想构建额外的模块(opencv_contrib) 到 OpenCV.
我按照此
我正在寻求帮助,我该如何解决.谢谢.
2017 年 5 月 29 日更新:这也适用于 OpenCV 3.2.0-dev.现在使用视觉Studio 2015 或 2017 没有错误.
cv2.pyd 现在会自动移动到站点包.您只需要复制 DLL.
<块引用>正如
- 按configure,会出现很多以红色突出显示的行.
- 在这些行出现之前,您必须指定您的编译器.(还可以根据您的需要选择正确的位版本,相同的程序适用于 32 位和 64 位)
- 选择您想要构建的任何内容,但最重要的是提供非自由模块的路径.
- 再次按configure,新行将以红色突出显示.
- 确保在按下生成之前取消选中 BUILD_opencv_contrib_world.
- CMake 的最后一步是按生成.
- 在继续之前确保
生成完成
.
- 打开空的构建,你会发现一堆文件.最重要的文件是
OpenCV.sln
.右键单击此 .sln 文件,然后使用 CMake 中使用的 Visual Studio 2013 打开它.
耐心等待这一步,下一步会花费很多时间.
- 按照下图中的顺序构建 3 个文件.将模式更改为
Release
.这些步骤大约需要 10 到 15 分钟.
- 复制所有
.dll
文件 [存在于opencv-3.1.0-devuildinRelease
] 和cv2.pyd
code> 并将它们粘贴到Pyhton27Libsite-packages
中的site-packages
目录中. - 验证构建打开 Python 并执行
import cv2
.如果没有错误,执行cv2.__version__
,你应该得到3.1.0-dev
.
如果有任何不清楚的地方,请观看本答案开头提供的教程.
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.
I follow the step in this 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_contribopencv_contrib/modules C:opencvsources
, there is an error.
I am looking for help how can I solve it. Thank you.
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.
As mentioned by @AleksandrUsarov in the comments section, this method still works for OpenCV 4.1.2, but you need to check
OPENCV_ENABLE_NONFREE
parameter as well.
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.
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-devuild
andopencv-3.1.0-devsources
. - 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
- Press configure, a lot of lines highlighted in red will appear.
- 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)
- Choose whatever you want to build, but the most important thing to do is to provide the path of the non-free modules.
- Press configure again and new lines will be highlighted in red.
- Make sure to uncheck BUILD_opencv_contrib_world before pressing generate.
- The last step with CMake is to press generate.
- Make sure
generating is done
before continuing.
- 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.
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.
- Copy all the
.dll
files [present atopencv-3.1.0-devuildinRelease
] and thecv2.pyd
and paste them in thesite-packages
directory inPyhton27Libsite-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屋!