1 .. _Windows_Installation:
\r
3 Installation in Windows
\r
4 ***********************
\r
6 .. include:: <isonum.txt>
\r
8 The description here was tested by the author using the Windows 7 SP1 **o**\ perating **s**\ ystem (*OS*). Nevertheless, it should also work on any other Windows OS too. If you encounter errors after following the steps described here feel free to contact us via our :opencv_group:`user group <>` and we will try to fix your problem.
\r
10 .. note:: To use the OpenCV library you have two options: :ref:`Windows_Install_Prebuild` or :ref:`CppTutWindowsMakeOwn`. While the first one is easier to complete, it only works if you are coding inside the latest Microsoft Visual Studio **i**\ ntegrated **d**\ evelopment **e**\ nvironments (*IDE*) and doesn't takes advantage of the most novel technologies we integrate into our library.
\r
12 .. _Windows_Install_Prebuild:
\r
14 Installation by using the pre-built libraries
\r
15 =============================================
\r
17 1. Open up a web browser and go to: http://sourceforge.net/projects/opencvlibrary/files/opencv-win/
\r
19 #. Open the folder for the latest version (currently this is 2.3).
\r
21 #. Choose a build you want to use and download it. The naming conventions used will show what kind of support they offer. For example:
\r
23 .. container:: enumeratevisibleitemswithsquare
\r
25 * *vs2010* means the Visual Studio
\r
26 * *win32* means that it is for 32 bit applications in the OS
\r
27 * *gpu* means that it includes the support for using your GPU in order to further increase the performance of the library).
\r
29 If you downloaded the source files present here see :ref:`CppTutWindowsMakeOwn`.
\r
31 #. Make sure you have admin rights. Start the setup and follow the wizard. Agree to the \" License Agreement \" .
\r
33 #. Adding the OpenCV library to the system path is a good decision unless you want to play around with multiple flavors of the same OpenCV version. 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 he 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.
\r
36 A good and safe way to check your systems **PATH** folders is by using the \"*Path Editor*\" application. You can download it `from here <http://www.redfernplace.com/software-projects/patheditor/>`_. Use this if you are not sure the systems path was updated with the OpenCV entry. You can also add manually new folders to the systems **PATH** by using this application.
\r
38 #. Most of the time it is a good idea to install the source files as this will allow for you to debug into the OpenCV library, if it is necessary. Therefore, just follow the default settings of the wizard and finish the installation.
\r
40 #. In the end you can check the installation at the chosen path. If you added the OpenCV Path to the system PATH inside the *Path Editor* you should see an entry with the *bin* folder of the OpenCV directory.
\r
42 .. image:: images/OpenCV_Install_Directory.jpg
\r
43 :alt: An example of how the installation directory should look in case of success.
\r
46 .. _CppTutWindowsMakeOwn:
\r
48 Installation by making your own libraries from the source files
\r
49 ===============================================================
\r
51 You may find the content of this tutorial also inside the following videos: `Part 1 <https://www.youtube.com/watch?v=NnovZ1cTlMs>`_ and `Part 2 <https://www.youtube.com/watch?v=qGNWMcfWwPU>`_, hosted on YouTube.
\r
55 <div align="center">
\r
56 <iframe title="Install OpenCV by using its source files - Part 1" width="560" height="349" src="http://www.youtube.com/embed/NnovZ1cTlMs?rel=0&loop=1" frameborder="0" allowfullscreen align="middle"></iframe>
\r
57 <iframe title="Install OpenCV by using its source files - Part 2" width="560" height="349" src="http://www.youtube.com/embed/qGNWMcfWwPU?rel=0&loop=1" frameborder="0" allowfullscreen align="middle"></iframe>
\r
60 If you are building your own libraries you can take either the source files from our latest:
\r
62 .. container:: enumeratevisibleitemswithsquare
\r
64 + stable and tested build - https://code.ros.org/svn/opencv/branches/
\r
65 + development build - https://code.ros.org/svn/opencv/trunk/
\r
67 While the later one may contain a couple of new and experimental algorithms, performance increases and interface improvements, be aware, that it may also contain many-many bugs. Using the first one is recommended in most of the cases. That is unless you are extending the OpenCV library itself or really need to most up to date version of it.
\r
69 Building the OpenCV library from scratch requires a couple of tools installed beforehand:
\r
71 .. container:: enumeratevisibleitemswithsquare
\r
73 + An **I**\ ntegrated **D**\ eveloper **E**\ nviroment (*IDE*) preferably, or just a C\C++ compiler that will actually make the binary files. Here I will use the `Microsoft Visual Studio <https://www.microsoft.com/visualstudio/en-us>`_. Nevertheless, you can use any other *IDE* that has a valid C\\C++ compiler.
\r
75 + Then |CMake|_ is a neat tool that will make the project files (for your choosen *IDE*) from the OpenCV source files. It will also allow an easy configuration of the OpenCV build files, in order to make binary files that fits exactly to your needs.
\r
76 .. |CMake| replace:: CMake
\r
77 .. _CMake: http://www.cmake.org/cmake/resources/software.html
\r
79 + A **S**\ ubversion **C**\ ontrol **S**\ ystem (*SVN*) to acquire the OpenCV source files. A good tool for this is |TortoiseSVN|_. Alternatively, you can just download an archived version of the source files from the `Sourceforge OpenCV page <http://sourceforge.net/projects/opencvlibrary/files/opencv-win/>`_.
\r
80 .. |TortoiseSVN| replace:: TortoiseSVN
\r
81 .. _TortoiseSVN: http://tortoisesvn.net/downloads.html
\r
83 OpenCV may come in multiple flavors. There is a "core" section that will work on its own. Nevertheless, they are a couple of tools, libraries made by other organizations (so called 3rd parties) that offer services of which the OpenCV may take advantage. These will improve in many ways its capabilities. In order to use any of them, you need to download and install them on your system.
\r
85 .. container:: enumeratevisibleitemswithsquare
\r
87 + The |Python_Libraries|_ are required to build the *Python interface* of OpenCV. For now use the version :file:`2.7.{x}`. This is also a must have if you want to build the *OpenCV documentation*.
\r
88 .. |Python_Libraries| replace:: Python libraries
\r
89 .. _Python_Libraries: http://www.python.org/getit/
\r
91 + |Numpy|_ is a scientific computing package for Python. Required for the *Python interface*.
\r
92 .. |Numpy| replace:: Numpy
\r
93 .. _Numpy: http://numpy.scipy.org/
\r
95 + |IntelTBB|_ is used inside OpenCV for parallel code snippets. Using this will make sure that the OpenCV library will take advantage of all the cores you have in your systems CPU.
\r
96 .. |IntelTBB| replace:: Intel |copy| Threading Building Blocks (*TBB*)
\r
97 .. _IntelTBB: http://threadingbuildingblocks.org/file.php?fid=77
\r
99 + |IntelIIP|_ may be used to improve the performance of color conversion, Haar training and DFT functions of the OpenCV library. Watch out as this isn't a *free* service.
\r
100 .. |IntelIIP| replace:: Intel |copy| Integrated Performance Primitives (*IPP*)
\r
101 .. _IntelIIP: http://software.intel.com/en-us/articles/intel-ipp/
\r
103 + OpenCV offers a somewhat fancier and more useful graphical user interface, than the default one by using the |qtframework|_. For a quick overview of what this has to offer look into the documentations *highgui* module, under the *Qt New Functions* section. Version 4.6 or later of the framework is required.
\r
104 .. |qtframework| replace:: Qt framework
\r
105 .. _qtframework: http://qt.nokia.com/downloads
\r
107 + |Eigen|_ is a C++ template library for linear algebra.
\r
108 .. |Eigen| replace:: Eigen
\r
109 .. _Eigen: http://eigen.tuxfamily.org/index.php?title=Main_Page#Download
\r
111 + The latest |CUDA_Toolkit|_ will allow you to use the power lying inside your GPU. This will drastically improve performance for some of the algorithms, like the HOG descriptor. Getting to work more and more of our algorithms on the GPUs is a constant effort of the OpenCV team.
\r
112 .. |CUDA_Toolkit| replace:: CUDA Toolkit
\r
113 .. _CUDA_Toolkit: http://developer.nvidia.com/cuda-downloads
\r
115 + |OpenEXR|_ source files are required for the library to work with this high dynamic range (HDR) image file format.
\r
116 .. |OpenEXR| replace:: OpenEXR
\r
117 .. _OpenEXR: http://www.openexr.com/downloads.html
\r
119 + The |OpenNI_Framework|_ contains a set of open source APIs that provide support for natural interaction with devices via methods such as voice command recognition, hand gestures and body motion tracking.
\r
120 .. |OpenNI_Framework| replace:: OpenNI Framework
\r
121 .. _OpenNI_Framework: http://www.openni.org/
\r
123 + |Miktex|_ is the best `TEX <https://secure.wikimedia.org/wikipedia/en/wiki/TeX>`_ implementation on the Windows OS. It is required to build the *OpenCV documentation*.
\r
124 .. |Miktex| replace:: Miktex
\r
125 .. _Miktex: http://miktex.org/2.9/setup
\r
127 + |Sphinx|_ is a python documentation generator and is the tool that will actually create the *OpenCV documentation*. This on its own requires a couple of tools installed, I will cover this in depth at the :ref:`How to Install Sphinx <HereInstallSphinx>` section.
\r
128 .. |Sphinx| replace:: Sphinx
\r
129 .. _Sphinx: http://sphinx.pocoo.org/
\r
131 Now I 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 those parts.
\r
133 .. _WindowsBuildLibrary:
\r
135 Building the library
\r
136 ^^^^^^^^^^^^^^^^^^^^
\r
138 1. Make sure you have a working IDE with a valid compiler. In case of the Microsoft Visual Studio just install it and make sure it starts up.
\r
140 #. Install |CMake|_. Simply follow the wizard, no need to add it to the path. The default install options are great. No need to change them.
\r
142 #. Install |TortoiseSVN|_. Choose the 32 or 64 bit version according to the type of OS you work in. Again follow the wizard, default options are good. Restart of your system is required.
\r
144 #. Choose a directory in your file system where you will download the OpenCV libraries. I recommend creating a new one that has short path and no special charachters in it, for example :file:`D:/OpenCV`. During this tutorial I'll suppose you've done so. If you use a different directory just change this front part of the path in my future examples. Then, :menuselection:`Right Click --> SVN Checkout...` in the directory.
\r
146 .. image:: images/TortoiseSVNCheckout.jpg
\r
147 :alt: The TortoiseSVN Checkout Menu
\r
150 A window will appear where you can select from what repository you want to download source files (1) and to which directory (2):
\r
152 .. image:: images/TortoiseSVNCheckoutWindow.jpg
\r
153 :alt: The TortoiseSVN Checkout Window
\r
156 Add here either ones of the versions described above. Then push the OK button and be patient as the repository currently is over 330MB to download. It will take some time until it is finished depending on your Internet connection.
\r
158 .. image:: images/SVNCheckOutProgress.jpg
\r
159 :alt: The TortoiseSVN Checkout Progress
\r
162 When you are done you should have a *opencv* and an *opencv_extra* directory as seen at (3).
\r
164 #. In this section I will cover installing the 3rd party libraries.
\r
166 a) Download the |Python_Libraries|_ and install it with the default options. You will need a couple other python extensions. Luckily installing all these may be automated by a nice tool called `Setuptools <http://pypi.python.org/pypi/setuptools#downloads>`_. Download and install again.
\r
168 #) .. _HereInstallSphinx:
\r
170 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.
\r
172 .. image:: images/cmsdstartwindows.jpg
\r
173 :alt: The Windows Command Startup
\r
176 .. image:: images/Sphinx_Install.jpg
\r
177 :alt: How to start the command window
\r
182 The *CD* navigation command works only inside a drive. For example if you are somewhere in the *C:* drive you cannot use it this to go to another drive (like for example *D:*). To do so you first need to change drives letters. For this simply enter the command *D:*. Then you can use the *CD* to navigate to specific folder inside the drive. Bonus tip: you can clear the screen by using the *CLS* command.
\r
184 This will also install its prerequisites `Jinja2 <http://jinja.pocoo.org/docs/>`_ and `Pygments <http://pygments.org/>`_.
\r
186 #) The easiest way to install |Numpy|_ is to just download its binaries from the `sourceforga page <http://sourceforge.net/projects/numpy/files/NumPy/>`_. Make sure your download and install exactly the binary for your python version (so for version :file:`2.7`).
\r
188 #) 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.
\r
190 .. image:: images/MiktexInstall.jpg
\r
191 :alt: The Miktex Install Screen
\r
194 #) For the |IntelTBB|_ download the source files and extract it inside a directory on your system. For example let there be :file:`D:/OpenCV/dep`. For installing the |IntelIIP|_ the story is the same. For exctracting the archives I recommend using the `7-Zip <http://www.7-zip.org/>`_ application.
\r
196 .. image:: images/IntelTBB.jpg
\r
197 :alt: The Miktex Install Screen
\r
200 #) In case of the |Eigen|_ library it is again a case of download and extract to the :file:`D:/OpenCV/dep` directory.
\r
202 #) Same as above with |OpenEXR|_.
\r
204 #) For the |OpenNI_Framework|_ you need to install both the `development build <http://www.openni.org/downloadfiles/opennimodules/openni-binaries/21-stable>`_ and the `PrimeSensor Module <http://www.openni.org/downloadfiles/opennimodules/openni-compliant-hardware-binaries/32-stable>`_.
\r
206 #) For the CUDA you need again two modules: the latest |CUDA_Toolkit|_ and the *CUDA Tools SDK*. Download and install both of them with a *complete* option by using the 32 or 64 bit setups according to your OS.
\r
208 #) In case of the |qtframework|_ 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 <http://qt.nokia.com/downloads>`_ page. Download the source files (not the installers!!!):
\r
210 .. image:: images/qtDownloadThisPackage.jpg
\r
211 :alt: Download this Qt Package
\r
214 Extract it into a nice and short named directory like :file:`D:/OpenCV/dep/qt/` .
\r
215 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 :menuselection:`All Programs --> Microsoft Visual Studio 2010 --> Visual Studio Tools --> Visual Studio Command Prompt (2010)`).
\r
217 .. image:: images/visualstudiocommandprompt.jpg
\r
218 :alt: The Visual Studio command prompt
\r
221 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:
\r
223 .. code-block:: bash
\r
225 configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg
\r
227 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):
\r
229 .. code-block:: bash
\r
233 After this set the Qt enviroment variables using the following command on Windows 7:
\r
235 .. code-block:: bash
\r
237 setx QTDIR D:/OpenCV/dep/qt/qt-everywhere-opensource-src-4.7.3
\r
239 Also, add the built binary files path to the system path by using the `Path Editor <http://www.redfernplace.com/software-projects/patheditor/>`_. In our case this is :file:`D:/OpenCV/dep/qt/qt-everywhere-opensource-src-4.7.3/bin`.
\r
243 If you plan on doing Qt application development you can also install at this point the *Qt Visual Studio Add-in*. After this you can make and build Qt applications without using the *Qt Creator*. Everything is nicely integrated into Visual Studio.
\r
245 #. Now start the *CMake (cmake-gui)*. You may again enter it in the start menu search or get it from the :menuselection:`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).
\r
247 .. image:: images/CMakeSelectBin.jpg
\r
248 :alt: Select the directories
\r
251 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.
\r
253 .. image:: images/CMake_Configure_Windows.jpg
\r
254 :alt: How CMake should look at build time.
\r
257 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 :menuselection:`WITH --> WITH_X` menu points (where *X* is the package abbreviation). Here are a list of current packages you can turn on or off:
\r
259 .. image:: images/CMakeBuildWithWindowsGUI.jpg
\r
260 :alt: The packages OpenCV may use
\r
263 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:
\r
265 .. image:: images/CMakePackageNotFoundWindows.jpg
\r
266 :alt: Constant for not found packages
\r
269 .. image:: images/CMakeOutputPackageNotFound.jpg
\r
270 :alt: Error (warning) thrown in output window of the CMake GUI
\r
273 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.
\r
274 Now I want to emphasize an option that you will definitely love: :menuselection:`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.
\r
276 .. image:: images/CMakeBuildOptionsOpenCV.jpg
\r
277 :alt: Set the Solution Folders and the parts you want to build
\r
280 Furthermore, you need to select what part of OpenCV you want to build.
\r
282 .. container:: enumeratevisibleitemswithsquare
\r
284 + *BUILD_DOCS* -> Build the documentation of OpenCV (there will be a separate project for building the HTML and the PDF files).
\r
285 + *BUILD_EXAMPLES* -> OpenCV comes with many example applications from which you may learn most of the libraries capabilities. This will also come handy to easily try out if OpenCV is fully functional on your computer.
\r
286 + *BUILD_JAVA_SUPPORT* -> This is a fresh addition to OpenCV, which slowly start to support the java language.
\r
287 + *BUILD_NEW_PYTHON_SUPPORT* -> Self-explanatory. Create the binaries to use OpenCV from the Python language.
\r
288 + *BUILD_PACKAGE* -> Build a project that will build an OpenCV installer. With this you can easily install your OpenCV flavor on other systems.
\r
289 + *BUILD_SHARED_LIBS* -> With this you can control to build DLL files (when turned on) or static library files (\*.lib) otherwise.
\r
290 + *BUILD_TESTS* -> Each module of OpenCV has a test project assigned to it. Building these test projects is also a good way to try out, that the modules work just as expected on your system too.
\r
292 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.
\r
293 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.
\r
294 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.
\r
296 .. image:: images/ChangeBuildVisualStudio.jpg
\r
297 :alt: Look here for changing the Build Type
\r
300 In the end you can observe the built binary files inside the bin directory:
\r
302 .. image:: images/OpenCVBuildResultWindows.jpg
\r
303 :alt: The Result of the build.
\r
306 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 :file:`Build/Doc/_html` for the HTML pages and within the :file:`Build/Doc` the PDF manuals.
\r
308 .. image:: images/WindowsBuildDoc.jpg
\r
309 :alt: The Documentation Projects
\r
312 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.
\r
314 .. image:: images/WindowsBuildInstall.jpg
\r
315 :alt: The Install Project
\r
318 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.
\r
322 To create an installer you need to install `NSIS <http://nsis.sourceforge.net/Download>`_. Then just build the *Package* project to build the installer into the :file:`Build/_CPack_Packages/{win32}/NSIS` folder. You can then use this to distribute OpenCV with your build settings on other systems.
\r
324 .. image:: images/WindowsOpenCVInstaller.jpg
\r
325 :alt: The Installer directory
\r
328 To test your build just go into the :file:`Build/bin/Debug` or :file:`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 via our :opencv_group:`user group <>`.
\r
329 If everything is okay the *contours.exe* output should resemble the following image (if built with Qt support):
\r
331 .. image:: images\WindowsQtContoursOutput.jpg
\r
332 :alt: A good output result
\r
337 If you use the GPU module (CUDA libraries) make sure you also upgrade to the latest drivers of your GPU. Error messages containing invalid entries in (or cannot find) the nvcuda.dll are caused mostly by old video card drivers. For testing the GPU (if built) run the *performance_gpu.exe* sample application.
\r
339 Now you can continue reading the tutorials with the :ref:`Windows_Visual_Studio_How_To` 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.
\r