OpenCV 3.1 with CUDA , QT , Python Complete Installation on Windows in With Extra Modules
Posted by Hemprasad Y. Badgujar on May 13, 2016
OpenCV 3.1 with CUDA , QT , Python Complete Installation on Windows in With Extra Modules
The description here was tested on Windows 8.1 Pro. 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 me.
Note : To use the OpenCV library you have two options: Installation by Using the Pre-built Libraries or Installation by Making Your Own Libraries from the Source Files. While the first one is easier to complete, it only works if you are coding with the latest Microsoft Visual Studio IDE and doesn’t take advantage of the most advanced technologies we integrate into our library.
I am going to skip Installation by Using the Pre-built Libraries is it is easier to install even for New User. So Let’s Work on Installation by Making Your Own Libraries from the Source Files (If you are building your own libraries you can take the source files from OpenCV Git repository.) Building the OpenCV library from scratch requires a couple of tools installed beforehand
Prerequisites Tools
- IDE : Microsoft Visual Studio. However, you can use any other IDE that has a valid CC++ compiler.
- Make Tool : CMake
- OpenCV source Files by GIT by : TortoiseGit or download source files from page on Sourceforge.
- Python libraries : from here distribution contains the MinGW compiler toolchain, which will be used by Cmake
- Numpy :Required for the Python interface
- Intel © Threading Building Blocks (TBB) is used inside OpenCV for parallel code snippets.
- Intel © Integrated Performance Primitives (IPP) may be used to improve the performance of color conversion.(Paid)
- Eigen is a C++ template library for linear algebra.
- CUDA Toolkit will allow you to use the power lying inside your GPU.
- JRE :Java run time environment
- OpenEXR source files are required for the library to work with this high dynamic range (HDR) image file format.
- OpenNI Framework contains a set of open source APIs that provide support for natural interaction with devices.
- Miktex is the best TEX implementation on the Windows OS. but we will use lyx
- Sphinx is a python documentation generator
- Kinect for Windows SDK, which is a free download for Kinet Support
- Environment Editor : Rapid Environment Editor
- OpenGL SDK and Libraries
- QT for GUI (for X64) and Visual Studio Add-in 1.2.4 for Qt5
- Qlib
Step By Step Prerequisites Setup
-
IDE : Microsoft Visual Studio. However, you can use any other IDE that has a valid CC++ compiler.
Installing By Downloading from the Product Website Start installing Visual Studio by going to Visual Studio Downloads on the MSDN website and then choosing the edition you want to download.here we will going to use Visual Studio 2012 / ISO keys with Visual Studio 2012 Update 4 /ISO and Step By Step Installing Visual Studio Professional 2012 -
Make Tool : Cmake is a cross-platform, open-source build system.
Download and install the latest stable binary version: here we will going to use CMake 3 Choose the windows installer (cmake-x.y.z-win32.exe) and install it. Letting the cmake installer add itself to your path will make it easier but is not required.
-
Download OpenCV source Files by GIT/Sourceforge by : TortoiseGit or download source files from page on Sourceforge.
The Open Source Computer Vision Library has >2500 algorithms, extensive documentation and sample code for real-time computer vision. It works on Windows, Linux, Mac OS X, Android and iOS.
-
Python and Python libraries : Installation notes
- It is recommended to uninstall any other Python distribution before installing Python(x,y)
- You may update your Python(x,y) installation via individual package installers which are updated more frequently — see the plugins page
- Please use the Issues page to request new features or report unknown bugs
- Python(x,y) can be easily extended with other Python libraries because Python(x,y) is compatible with all Python modules installers: distutils installers (.exe), Python eggs (.egg), and all other NSIS (.exe) or MSI (.msi) setups which were built for Python 2.7 official distribution – see the plugins page for customizing options
- Another Python(x,y) exclusive feature: all packages are optional (i.e. install only what you need)
- Basemap users (data plotting on map projections): please see the AdditionalPlugins
-
Sphinx is a python documentation generator
After installation, you better add the Python executable directories to the environment variable PATH in order to run Python and package commands such as sphinx-build easily from the Command Prompt.
-
Right-click the “My Computer” icon and choose “Properties”
-
Click the “Environment Variables” button under the “Advanced” tab
-
If “Path” (or “PATH”) is already an entry in the “System variables” list, edit it. If it is not present, add a new variable called “PATH”.
-
-
Right-click the “My Computer” icon and choose “Properties”
-
Click the “Environment Variables” button under the “Advanced” tab
-
If “Path” (or “PATH”) is already an entry in the “System variables” list, edit it. If it is not present, add a new variable called “PATH”.
-
Add these paths, separating entries by ”;”:
C:\Python27
– this folder contains the main Python executableC:\Python27\Scripts
– this folder will contain executables added by Python packages installed with pip (see below)
This is for Python 2.7. If you use another version of Python or installed to a non-default location, change the digits “27” accordingly.
-
Now run the Command Prompt. After command prompt window appear, type
python
and Enter. If the Python installation was successful, the installed Python version is printed, and you are greeted by the prompt>>>
. TypeCtrl+Z
and Enter to quit.Add these paths, separating entries by ”;”:
- C:\Python27 – this folder contains the main Python executable
- C:\Python27\Scripts – this folder will contain executables added by Python packages installed with easy_install (see below)
This is for Python 2.7. If you use another version of Python or installed to a non-default location, change the digits “27” accordingly.
After installation, you better add the Python executable directories to the environment variable
PATH
in order to run Python and package commands such assphinx-build
easily from the Command Prompt. -
Install the pip command
Python has a very useful pip command which can download and install 3rd-party libraries with a single command. This is provided by the Python Packaging Authority(PyPA): https://groups.google.com/forum/#!forum/pypa-dev
To install pip, download https://bootstrap.pypa.io/get-pip.py and save it somewhere. After download, invoke the command prompt, go to the directory with
get-pip.py
and run this command:C:\> python get-pip.py
Now pip command is installed. From there we can go to the Sphinx install.
Note :
pip
has been contained in the Python official installation after version- of Python-3.4.0 or Python-2.7.9.
-
-
-
Installing Sphinx with pip
If you finished the installation of pip, type this line in the command prompt:
C:\> pip install sphinx
After installation, type sphinx-build -h on the command prompt. If everything worked fine, you will get a Sphinx version number and a list of options for this command.
That it. Installation is over. Head to First Steps with Sphinx to make a Sphinx project.
Now run the Command Prompt. After command prompt window appear, type python and Enter. If the Python installation was successful, the installed Python version is printed, and you are greeted by the prompt>>> . TypeCtrl+Z and Enter to quit.
-
Install the easy_install command
Python has a very useful easy_install command which can download and install 3rd-party libraries with a single command. This is provided by the “setuptools” project: https://pypi.python.org/pypi/setuptools.
To install setuptools, download https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py and save it somewhere. After download, invoke the command prompt, go to the directory with ez_setup.py and run this command:
C:\> python ez_setup.py
Now setuptools and its easy_install command is installed. From there we can go to the Sphinx install.
Installing Sphinx with easy_install
If you finished the installation of setuptools, type this line in the command prompt:
C:\> easy_install sphinx
After installation, type sphinx-build on the command prompt. If everything worked fine, you will get a Sphinx version number and a list of options for this command.
- Numpy is a scientific computing package for Python. Required for the Python interface.
Try the (unofficial) binaries in this site: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
You can get numpy 1.6.2 x64 with or without Intel MKL libs to Python 2.7
I suggest WinPython, a Python 2.7 distribution for Windows with both 32- and 64-bit versions.
It is also worth considering the Anaconda Python distribution. http://continuum.io/downloads
-
Numpy :Required for the Python interface abve Installation of python alosho included with Numpy and Scipy libraries
-
Intel © Threading Building Blocks (TBB) is used inside OpenCV for parallel code snippets. Download Here
- Download TBB
- Go to TBB download page to download the open source binary releases. I choose Commercial Aligned Release, because this has the most stable releases. I downloaded tbb43_20141204os, TBB 4.3 Update 3, specifically tbb43_20141204os for Windows. The release has the header files as well as the import library and DLL files prebuilt for Microsoft Visual C++ 8.0 and 9.0 on both x86(IA32) and x64(intel64). If you are aggressive and need the source code of TBB, you can try stable releases or development releases.
- Install TBB
- Extract the files in the zip file to a local directory, for example, C:\TBB. You should find tbb22_013oss under it. This is the installation directory, and doc, example, include etc should be directly under the installation folder.
- Set a Windows environment variable TBB22_INSTALL_DIR to the above directory, e.g., C:\TBB\tbb22_013oss.
- Develop with TBB
- Add $(TBB22_INSTALL_DIR)\include to your C++ project’s additional include directories.
- Add $(TBB22_INSTALL_DIR)\<arch>\<compiler>\lib (e.g., $(TBB22_INSTALL_DIR)\ia32\vc9\lib) to your project’s additional library directories.
- Add to your project’s additional dependencies tbb.lib (Release) or tbb_debug.lib (Debug).
- Write your C++ code to use TBB. See code below as an example.
- Deploy with TBB
- The TBB runtime is in TBB DLLs (tbb.dll/tbbmalloc.dll/tbbmalloc_proxy.dll for Release, tbb_debug.dll/tbbmalloc_debug.dll/tbbmalloc_proxy_debug.dll for Debug). They can be found in $(TBB22_INSTALL_DIR)\\\bin.
- Your executable should have these DLLs in the same folder for execution.
Intel © Integrated Performance Primitives (IPP) may be used to improve the performance of color conversion.(Paid)
Intel Parallel Studio XE 2015 – Cluster Edition includes everything in the Professional edition (compilers, performance libraries, parallel models, performance profiler, threading design/prototyping, and memory & thread debugger). It adds a MPI cluster communications library, along with MPI error checking and tuning to design, build, debug and tune fast parallel code that includes MPI.
- Download TBB
-
Eigen is a C++ template library for linear algebra.
“install” Eigen?
In order to use Eigen, you just need to download and extract Eigen‘s source code (see the wiki for download instructions). In fact, the header files in the
Eigen
subdirectory are the only files required to compile programs using Eigen. The header files are the same for all platforms. It is not necessary to use CMake or install anything.simple first program
Here is a rather simple program to get you started.
#include <iostream>#include <Eigen/Dense>using Eigen::MatrixXd;int main(){MatrixXd m(2,2);m(0,0) = 3;m(1,0) = 2.5;m(0,1) = -1;m(1,1) = m(1,0) + m(0,1);std::cout << m << std::endl;} -
Installing CUDA Development Tools
The setup of CUDA development tools on a system running the appropriate version of Windows consists of a few simple steps:
- Verify the system has a CUDA-capable GPU.
- Download the NVIDIA CUDA Toolkit.
- Install the NVIDIA CUDA Toolkit.
- Test that the installed software runs correctly and communicates with the hardware.
- CUDA Toolkit will allow you to use the power lying inside your GPU. we will going to use CUDA 7.5 Toolkit
To verify that your GPU is CUDA-capable, open the Control Panel ( ) and double click on System. In the System Propertieswindow that opens, click the Hardware tab, then Device Manager. Expand the Display adapters entry. There you will find the vendor name and model of your graphics card. If it is an NVIDIA card that is listed inhttp://developer.nvidia.com/cuda-gpus, your GPU is CUDA-capable.
The Release Notes for the CUDA Toolkit also contain a list of supported products.
The NVIDIA CUDA Toolkit is available at http://developer.nvidia.com/cuda-downloads.
Choose the platform you are using and download the NVIDIA CUDA Toolkit
The CUDA Toolkit contains the CUDA driver and tools needed to create, build and run a CUDA application as well as libraries, header files, CUDA samples source code, and other resources.
Download Verification
The download can be verified by comparing the MD5 checksum posted at http://developer.nvidia.com/cuda-downloads/checksums with that of the downloaded file. If either of the checksums differ, the downloaded file is corrupt and needs to be downloaded again.
To calculate the MD5 checksum of the downloaded file, follow the instructions at http://support.microsoft.com/kb/889768.
Before installing the toolkit, you should read the Release Notes, as they provide details on installation and software functionality.
Note: The driver and toolkit must be installed for CUDA to function. If you have not installed a stand-alone driver, install the driver from the NVIDIA CUDA Toolkit.Graphical Installation
Install the CUDA Software by executing the CUDA installer and following the on-screen prompts.
Silent Installation
Alternatively, the installer can be executed in silent mode by executing the package with the -s flag. Additional flags can be passed which will install specific subpackages instead of all packages. Allowed subpackage names are: CUDAToolkit_6.5, CUDASamples_6.5, CUDAVisualStudioIntegration_6.5, and Display.Driver. For example, to install only the driver and the toolkit components:
.exe -s CUDAToolkit_6.5 Display.Driver
This will drastically improve performance for some algorithms (e.g the HOG descriptor). Getting more and more of our algorithms to work on the GPUs is a constant effort of the OpenCV .
-
JRE :Java run time environment
Installing Ant The binary distribution of Ant consists of the following directory layout:
ant +--- README, LICENSE, fetch.xml, other text files. //basic information +--- bin // contains launcher scripts | +--- lib // contains Ant jars plus necessary dependencies | +--- docs // contains documentation | | | +--- images // various logos for html documentation | | | +--- manual // Ant documentation (a must read ;-) | +--- etc // contains xsl goodies to: // - create an enhanced report from xml output of various tasks. // - migrate your build files and get rid of 'deprecated' warning // - ... and more ;-)
Only the
bin
andlib
directories are required to run Ant. To install Ant, choose a directory and copy the distribution files there. This directory will be known as ANT_HOME.
Before you can run Ant there is some additional set up you will need to do unless you are installing the RPM version from jpackage.org:
- Add the
bin
directory to your path. - Set the
ANT_HOME
environment variable to the directory where you installed Ant. On some operating systems, Ant’s startup scripts can guessANT_HOME
(Unix dialects and Windows NT/2000), but it is better to not rely on this behavior. - Optionally, set the
JAVA_HOME
environment variable (see the Advanced section below). This should be set to the directory where your JDK is installed.
Operating System-specific instructions for doing this from the command line are in the Windows, Linux/Unix (bash), and Linux/Unix (csh) sections. Note that using this method, the settings will only be valid for the command line session you run them in. Note: Do not install Ant’s ant.jar file into the lib/ext directory of the JDK/JRE. Ant is an application, whilst the extension directory is intended for JDK extensions. In particular there are security restrictions on the classes which may be loaded by an extension.
Windows Note: | |
The ant.bat script makes use of three environment variables – ANT_HOME, CLASSPATH and JAVA_HOME. Ensure that ANT_HOME and JAVA_HOME variables are set, and that they do not have quotes (either ‘ or “) and they do not end with \ or with /. CLASSPATH should be unset or empty. |
Check Installation
You can check the basic installation with opening a new shell and typing ant. You should get a message like this
Buildfile: build.xml does not exist! Build failed
Apache Ant(TM) version 1.9.2 compiled on July 8 2013
If this does not work ensure your environment variables are set right. They must resolve to:
- required: %ANT_HOME%\bin\ant.bat
- optional: %JAVA_HOME%\bin\java.exe
- required: %PATH%=…maybe-other-entries…;%ANT_HOME%\bin;…maybe-other-entries…
-
OpenEXR source files are required for the library to work with this high dynamic range (HDR) image file format.
-
OpenNI Framework contains a set of open source APIs that provide support for natural interaction with devices.
Guideline How to Install OpenNI 2.0 + Nite 2.0 + Kinect SDK 1.8 + windows 7 32/64 bit UPDATED [14th January 2013] Kinect Installation Guide Document[ View / Download] https://docs.google.com/file/d/0B3e4_6C5_YOjcmZpak12Q2MyZHM/edit Kinect Installation Video [download] https://drive.google.com/file/d/0B3e4_6C5_YOjQjRXMUNnNW5xN3M/edit?usp=sharing
-
Step 1
Download File Required Kinect SDK 1.8 Web ~ http://www.microsoft.com/en-us/kinectforwindows/develop/developer-downloads.aspx Kinect Developer Toolkits 1.8 ~ https://drive.google.com/file/d/0B3e4_6C5_YOjaW85QzVKR2lYVkU/edit?usp=sharing KinectRuntime 1.8 ~ https://drive.google.com/file/d/0B3e4_6C5_YOjS1dGdHcwMjJGWDQ/edit?usp=sharing Kinect SDK 1.8 ~ https://drive.google.com/file/d/0B3e4_6C5_YOjeUowcDhUNmRMV0U/edit?usp=sharing OpenNI 2.2 32bits / 64bits http://www.openni.org/openni-sdk/ or http://structure.io/openni OpenNi 32 bit ~ https://drive.google.com/file/d/0B3e4_6C5_YOjMS1EQWh6VFhWbnc/edit?usp=sharing OpenNi 64 bit ~ https://drive.google.com/file/d/0B3e4_6C5_YOjYmVPQzhwazhBOUE/edit?usp=sharing Nite 2.2 http://www.openni.org/files/nite/ Nite 32 bit ~ https://drive.google.com/file/d/0B3e4_6C5_YOjQWtCcVl3VnRsWG8/edit?usp=sharing Nite 64 bit ~https://drive.google.com/file/d/0B3e4_6C5_YOjOGIySEluYkNibEE/edit?usp=sharing
-
Step 2
a. Install Kinect for Windows SDK b. Install OpenNI 2.2 SDK 32bits / 64bits ( install both 64 bits and 32bits if u are using win64) c. Install Nite 2.2 ( install both 64 bits and 32bits if u are using win64)
-
Step 3 Run NiViewer.exe for Testing. It will be located at 64bits ~ (OpenNI ) C:\Program Files\OpenNI2\Samples\Bin ~ (Prime Sensor) C:\Program Files\PrimeSense\NiTE2\Samples\Bin 32bits ~(OpenNI ) C:\Program Files (x86) \OpenNI2\Samples\Bin ~ (Prime Sensor) C:\Program Files (x86) \PrimeSense\NiTE2\Samples\Bin Programmer Guide http://www.openni.org/openni-programmers-guide/
-
Miktex is the best TEX implementation on the Windows OS. but we will use lyx
Install the programs found below in the order shown.
- Install MiKTeX This is the core program used byLyx to output nice documents. After installing it, make sure thatMiKTeX is able to install missing packages on-the-fly. To do this, go toStart→Programs→MiKTeX→MiKTeX Options →General→Package installation→Ask me first.
Note: You should be able to use other LaTeX packages instead of MikTeX. One example is TeXLive, a CD-based version.
- Install Ghostscript. Thisis used to create Postscript documents, as well as for viewing .ps and .eps files insideLyX.
- Install ImageMagick (choose the file “ImageMagick-6.x.x-Q16-windows-dll.exe”). ImageMagickis used to convert images into formats thatLyX can understand.
- Optionally, install GSview, which lets you view Postscript files. Thisis recommended.
- Optionally, install a PDF viewer, if you do not already have one. This is also recommended. Adobe Reader is the most common. Alternates include the more compact Foxit reader and GSview, which shows PDF files in addition to Postscript.
- Download these math fonts math and install them in windows fonts folder. To install the fonts useStart→Settings→Control Panel→Fonts and thenFile→Install New Font. These fontsare used to display symbols in theLyX math editor.
- Finally, install LyX 1.4.1 for Windows. Installing it last ensures that it can find the programs listed above. If you install or update one of those programs later, go to Reconfigure in the Tools menu to make LyX look for it.
- Install MiKTeX This is the core program used byLyx to output nice documents. After installing it, make sure thatMiKTeX is able to install missing packages on-the-fly. To do this, go toStart→Programs→MiKTeX→MiKTeX Options →General→Package installation→Ask me first.
-
Kinect for Windows SDK, which is a free download for Kinet Support
-
Environment Editor : Rapid Environment Editor
-
OpenGL SDK and Libraries
-
Cg Toolkit Download
-
QT for GUI (for X64) and Visual Studio Add-in 1.2.4 for Qt5
Extract it into a directory like C:\Qt Open a shell, cd to the directory containing the extracted Qt files and enter the following command:
configure.exe -release -no-webkit -no-phonon -no-phonon-backend -no-script -no-scripttools -no-qt3support -no-multimedia -no-ltcg
This will take around 10 minutes. Then enter the next command that will take a lot longer (can easily take even more than a full hour): make Create a system environment variable QTDIR : C:\Qt\qt-everywhere-opensource-src-4.8.2 Add %QTDIR%\bin at the front of the system PATH.
setx -m QTDIR D:/OpenCV/dep/qt/qt-everywhere-opensource-src
Leave a Reply