Building and Compiling
opencv 3.1.0-dev to get an access for non free modules can be a headache for some people especially on Windows machine. Unlike Ubuntu, setting up opencv for Windows takes some time and requires a couple pf dependencies to be installed first before building and compiling.
The programs you should download and install before going further in any step are:
If you are going to download either Python for Win32, you should also download CMake for Win32 even if you are using a 64-bit machine.
It's recommended to download the 32-bit programs because some Python libraries are only supported for 32-bit machines, so to stay away from troubles, just install everything in 32-bit version.
After Installing all the above dependencies, restart your PC and then you will be ready to continue to the next step.
If you are not the type of person who prefers to read, you can watch this tutorial. The tutorial takes you from here to the end of this documentation.
You will need to get opencv and opencv_contrib from github. You can find both at:
Create a directory named opencv-3.1.0 where in this director you will make another two directories one for the build and one for the sources. You will put the two downloaded zip files in the sources file after extraction.
For example your opencv-3.1.0 directory is located in the C drive, so you will have three paths:
The third directory will include two paths:
Now it's done with preparation. Lets make some useful stuff.
Run CMake as an administator. A window like this will appear and you will have to provide two directories one for the sources and the other for where the opencv will be compiled. The below image can help you more better than words.
Next click configure and you will be promoted to provide the generators; i.e. compilers; for opencv. You have to provide the
cl.exe located in Microsoft Visual Studio 2013. Click specify native generators and a pop up window like the following will appear,
The paths will be something like this:
C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/cl.exe. Provide your path for both C and C++ fields. Click finish and wait until configuring is done. You should get zero errors if you were following all the previous steps correctly.
After CMake finishes configuring, you will see new items appearing in the CMake window that are highlighted in red. It will be something like:
Check the builds you need by clicking on the small square box. Search for
OPENCV_EXTRA_MODULES_PATH line and provide the modules directory within opencv_contrib within the sources directory.
Once you have finished all you need and provided the path for the extra modules press configure again to update. The previously highlighted lines will no longer be highlighted and new fields will be highlighted in red instead.
Also check the boxes for whatever you need to build.
Make sure that BUILD_opencv_contrib_world and BUILD_opencv_world are both unchecked. There is probably a bug where an error occurs when any of the latter are checked.
At the end of this step click Generate and you will be done with CMake and you can close it. If there are no errors, you will get a message at the end of the lower pane saying Generating done.
Open up the build directory located in opencv-3.1.0 and you will find a bunch of new folders and files inside it. It was an empty folder at the beginning of this process.
You will only deal with
OpenCV.sln file and don't do anything with the rest files. Open this file with the version that used while compiling in the CMake in the previous step. It has to be
Visual Microsoft 2013.
When you open the .sln file, please be patient as it takes some time to prepare everything for building. When Ready is steady (not changing) you can start building your targets. Start building as numbered in the image below. Also make sure that the
Solution Configuration is
When building is finished, you will need to copy and paste a couple of files from the build directory into the
cv2.pyd file and copy it to the
site-packages directory in
cv2.pyd should be present in
C:\opencv-3.1.0\build\lib\Release. After that, copy only the .dll files inside
C:\opencv-3.1.0\build\bin\Release into the parent directory of
Python27 at this location
At the end of this step, restart you PC.
Open IDLE and within the Python shell type:
>>> import cv2 >>> print cv2.__version__ 3.1.0-dev
import cv2 import numpy as np img = cv2.imread('<your_image>') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) cv2.imshow('image', img) cv2.imshow('gray', gray) cv2.waitKey(0) cv2.destroyAllWindows()