OpenCV
3.2.0
Open Source Computer Vision
|
The description here was tested on Windows 7 SP1. Nevertheless, it should also work on any other relatively modern version of Windows OS. If you encounter errors after following the steps described below, feel free to contact us via our OpenCV Q&A forum. We'll do our best to help you out.
You can check the installation at the chosen path as you can see below.
You may find the content of this tutorial also inside the following videos: Part 1 and Part 2, hosted on YouTube.
warning
These videos above are long-obsolete and contain inaccurate information. Be careful, since solutions described in those videos are no longer supported and may even break your install.
If you are building your own libraries you can take the source files from our Git repository.
Building the OpenCV library from scratch requires a couple of tools installed beforehand:
OpenCV may come in multiple flavors. There is a "core" section that will work on its own. Nevertheless, there is a couple of tools, libraries made by 3rd parties that offer services of which the OpenCV may take advantage. These will improve its capabilities in many ways. In order to use any of them, you need to download and install them on your system.
2.7.{x}
. This is also a must if you want to build the OpenCV documentation.Now we will describe the steps to follow for a full build (using all the above frameworks, tools and libraries). If you do not need the support for some of these you can just freely skip this section.
D:/OpenCV
. For this tutorial I'll suggest you do so. If you use your own path and know, what you're doing – it's OK.D:/OpenCV
).Installing Sphinx is easy once you have installed Setuptools. This contains a little application that will automatically connect to the python databases and download the latest version of many python scripts. Start up a command window (enter cmd into the windows start menu and press enter) and use the CD command to navigate to your Python folders Script sub-folder. Here just pass to the easy_install.exe as argument the name of the program you want to install. Add the sphinx argument.
This will also install its prerequisites Jinja2 and Pygments.
2.7
).Download the Miktex and install it. Again just follow the wizard. At the fourth step make sure you select for the *"Install missing packages on-the-fly"* the Yes option, as you can see on the image below. Again this will take quite some time so be patient.
For the Intel Threading Building Blocks (TBB) download the source files and extract it inside a directory on your system. For example let there be D:/OpenCV/dep
. For installing the Intel Integrated Performance Primitives (IPP) the story is the same. For exctracting the archives I recommend using the 7-Zip application.
<your Program Files(x86) directory>/Intel/IPP Preview */ipp directory
. Here * denotes the particular preview name.D:/OpenCV/dep
directory.In case of the Qt framework you need to build yourself the binary files (unless you use the Microsoft Visual Studio 2008 with 32 bit compiler). To do this go to the Qt Downloads page. Download the source files (not the installers!!!):
Extract it into a nice and short named directory like D:/OpenCV/dep/qt/
. Then you need to build it. Start up a Visual Studio Command Prompt (2010) by using the start menu search (or navigate through the start menu All Programs –> Microsoft Visual Studio 2010 –> Visual Studio Tools –> Visual Studio Command Prompt (2010)).
Now navigate to the extracted folder and enter inside it by using this console window. You should have a folder containing files like Install, Make and so on. Use the dir command to list files inside your current directory. Once arrived at this directory enter the following command:
Completing this will take around 10-20 minutes. Then enter the next command that will take a lot longer (can easily take even more than a full hour):
After this set the Qt enviroment variables using the following command on Windows 7:
Also, add the built binary files path to the system path by using the PathEditor. In our case this is D:/OpenCV/dep/qt/qt-everywhere-opensource-src-4.7.3/bin
.
Now start the CMake (cmake-gui). You may again enter it in the start menu search or get it from the All Programs –> CMake 2.8 –> CMake (cmake-gui). First, select the directory for the source files of the OpenCV library (1). Then, specify a directory where you will build the binary files for OpenCV (2).
Press the Configure button to specify the compiler (and IDE) you want to use. Note that in case you can choose between different compilers for making either 64 bit or 32 bit libraries. Select the one you use in your application development.
CMake will start out and based on your system variables will try to automatically locate as many packages as possible. You can modify the packages to use for the build in the WITH –> WITH_X menu points (where X is the package abbreviation). Here are a list of current packages you can turn on or off:
Select all the packages you want to use and press again the Configure button. For an easier overview of the build options make sure the Grouped option under the binary directory selection is turned on. For some of the packages CMake may not find all of the required files or directories. In case of these CMake will throw an error in its output window (located at the bottom of the GUI) and set its field values, to not found constants. For example:
For these you need to manually set the queried directories or files path. After this press again the Configure button to see if the value entered by you was accepted or not. Do this until all entries are good and you cannot see errors in the field/value or the output part of the GUI. Now I want to emphasize an option that you will definitely love: ENABLE –> ENABLE_SOLUTION_FOLDERS. OpenCV will create many-many projects and turning this option will make sure that they are categorized inside directories in the Solution Explorer. It is a must have feature, if you ask me.
Furthermore, you need to select what part of OpenCV you want to build.
Press again the Configure button and ensure no errors are reported. If this is the case you can tell CMake to create the project files by pushing the Generate button. Go to the build directory and open the created OpenCV solution. Depending on just how much of the above options you have selected the solution may contain quite a lot of projects so be tolerant on the IDE at the startup. Now you need to build both the Release and the Debug binaries. Use the drop-down menu on your IDE to change to another of these after building for one of them.
In the end you can observe the built binary files inside the bin directory:
For the documentation you need to explicitly issue the build commands on the doc project for the PDF files and on the doc_html for the HTML ones. Each of these will call Sphinx to do all the hard work. You can find the generated documentation inside the Build/Doc/_html
for the HTML pages and within the Build/Doc
the PDF manuals.
To collect the header and the binary files, that you will use during your own projects, into a separate directory (simillary to how the pre-built binaries ship) you need to explicitely build the Install project.
This will create an Install directory inside the Build one collecting all the built binaries into a single place. Use this only after you built both the Release and Debug versions.
To test your build just go into the Build/bin/Debug
or Build/bin/Release
directory and start a couple of applications like the contours.exe. If they run, you are done. Otherwise, something definitely went awfully wrong. In this case you should contact us at our Q&A forum. If everything is okay the contours.exe output should resemble the following image (if built with Qt support):
First we set an enviroment variable to make easier our work. This will hold the build directory of our OpenCV library that we use in our projects. Start up a command window and enter:
Here the directory is where you have your OpenCV binaries (extracted or built). You can have different platform (e.g. x64 instead of x86) or compiler type, so substitute appropriate value. Inside this you should have two folders called lib and bin. The -m should be added if you wish to make the settings computer wise, instead of user wise.
If you built static libraries then you are done. Otherwise, you need to add the bin folders path to the systems path. This is because you will use the OpenCV library in form of *"Dynamic-link libraries"* (also known as DLL). Inside these are stored all the algorithms and information the OpenCV library contains. The operating system will load them only on demand, during runtime. However, to do this the operating system needs to know where they are. The systems PATH contains a list of folders where DLLs can be found. Add the OpenCV library path to this and the OS will know where to look if he ever needs the OpenCV binaries. Otherwise, you will need to copy the used DLLs right beside the applications executable file (exe) for the OS to find it, which is highly unpleasent if you work on many projects. To do this start up again the PathEditor and add the following new entry (right click in the application to bring up the menu):
Save it to the registry and you are done. If you ever change the location of your build directories or want to try out your applicaton with a different build all you will need to do is to update the OPENCV_DIR variable via the setx command inside a command window.
Now you can continue reading the tutorials with the How to build applications with OpenCV inside the "Microsoft Visual Studio" section. There you will find out how to use the OpenCV library in your own projects with the help of the Microsoft Visual Studio IDE.