问题
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_contrib\opencv_contrib/modules C:\opencv\sources, there is an error.
I am looking for help how can I solve it. Thank you.
回答1:
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.
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-devand in this directory create other two directories one calledbuildand the other calledsources. Thepathswill beopencv-3.1.0-dev\buildandopencv-3.1.0-dev\sources. - Unzip
opencv-master.zipandopencv_contrib-master.zip - In the sources directory created in step 4, paste
opencvandopencv_contribdirectories - 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 donebefore 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
.dllfiles [present atopencv-3.1.0-dev\build\bin\Release] and thecv2.pydand paste them in thesite-packagesdirectory 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.
回答2:
For Python 3.6/3.5 you could use *.whl (Python on Wheels) module from here:
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 page and then add opencv-contrib-python module:
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.
回答3:
no need for complex stuff, just uninstall the version of opencv you have and do:
pip install opencv-contrib-python
Good luck, Amber
回答4:
The answer of foo bar is 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.
回答5:
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
However, it was necessary to use Visual Studio 12 2013, other versions did not work.
来源:https://stackoverflow.com/questions/37517983/opencv-install-opencv-contrib-on-windows