OpenCV installation walkthrough



OpenCV installation walkthroughGuide targetThis guide aims to describe all steps to install OpenCV on a Windows base system. It is not a replacement in any way of the official one that is by far the best place to start from but it target to address issues I had and that are probably related to new versions of the software involved or even to lack of knowledge on my side.Moreover, solutions reported here are taken from different forums/sites and you need to thank the original solver, just searching for them one by one could take big amount of time: they are here to save time and thanks to the original solver.EnvironmentThe machine is equipped with Windows 8.1 Pro 64bits. Same steps can be applied in 32 bits systems without small changes almost all related to installation packages.10GB free for all the installations: they take space.What to buildThe target is to install OpenCV 2.4.10 with some feature enabled:TBB support (to have Haar Cascades generation faster) VTK support Qt support (to have same graphical environment for Windows, Linux and Raspberry development)Documentation enabled.These options are not mandatory and, depending on what you would like to do, can be leave disabled.Pre-requisitesWe need some software to being able to enable the feature listed above:OpenCV (version 2.4.10 is installed, ) The executable package is download, it will install OpenCV together with sources. We will use these sources to compile the MinGW version.TBB (Threading Building Blocks, Intel?, ) We are going to compile the package for our specific environment so sources have to be downloaded.VTK (The Visualization Toolkit, ) We are going to compile the package for our specific environment so sources have to be downloaded.CMake (version 3.1.0, )Binary installation package is available.MikTex (TeX/LaTeX implementation, )Binary installation package is available.Qt5 (Qt5.4.0 package for with MinGW4.9.1, )Binary installation package is available.Java (JDK7u80 64bit, ) Binary installation package is available.Python (2.7, Anaconda installation package, ) Binary installation package is available.Sphinx () Binary installation package is available.MinGW (version 4.9.1) This package will be installed with Qt5.4.0: we will use this one to compile other software we need.Here are listed specific versions but the same process shall work with packages/sources more recent.-3398-257Even if not strictly mandatory I suggest to install all packages under a path without any space. The installation directory C:\Bin is used through this guide for all software.Some environmental variable will be created and the PATH one will be modified so from the system applet or from regedit (Windows registry editor program) we will need to operate on these variables.We will install the different software following the order below.CMake installationAfter downloading the package, current version is cmake-3.1.0-win32-x86.exe, execute and install it with defaults or change as per general suggestion above (i.e. installation path is C:\Bin\CMake). If the automatic modification of the path is selected I get an error reporting that the PATH is too long and the operation fails so I do it manually at the end of the installation, adding C:\Bin\CMake\bin in the PATH variable. left40931During the installation of VTK and OpenCV, that use CMake, it is assumed you use the default MinGW compiler that is automatically recognized after installing the Qt package.MikTex installationAfter package download, current is basic-miktex-2.9.5105.exe, accept defaults (changing the path if you want to) and proceed. I installed it under C:\Bin\MiKTeX2.9 and I add C:\Bin\MiKTeX2.9\miktex\bin to the path.JDK installationDownload package jdk-7u80-ea-bin-b03-windows-x64-19_nov_2014.exe and run it. I installed it under C:\Bin\Java\jdk1.7.0_80. Follow the installation steps: nothing has to be done in addition.PythonDownload Anaconda-2.1.0-Windowsx-86_64.exe and install it. This versions comes with Numpy package already available so we will save time and problems. We will install it under C:\Bin\Anaconda. Follow the installation steps: nothing has to be done in addition.SphinxDownload sphinx-2.2.6-release-win64-full.zip and unzip it in C:\Bin\sphinx-2.2.6.Change all occurrences of @CONFDIR@ with C:\Bin\sphinx-2.2.6 in the file sphinx.conf.in.Open a command prompt as administrator and run the following command from the bin directory in the installation folder:C:\Bin\sphinx-2.2.6\bin>searchd.exe --install --config c:\Bin\sphinx-2.2.6\sphinx.conf.in --servicename SphinxSearchYou should see something like:Sphinx 2.2.6-id64-release (r4843)Copyright (c) 2001-2014, Andrew AksyonoffCopyright (c) 2008-2014, Sphinx Technologies Inc ()Installing service...Service 'SphinxSearch' installed successfully.left64633In any case, in the file doc/sphinx.txt it is described what to do for a correct installation.Qt installationDownload package qt-opensource-windows-x86-mingw491_opengl-5.4.0.exe and run it. I installed it under C:\Bin\Qt\Qt5.4.0. When prompted in the installer add Tools -> Ming 4.9.1 option and leave the rest as default. Follow the installation steps.At the end of the installation, add the MinGW binary directory to the PATH variable: C:\Bin\Qt\Qt5.4.0\Tools\mingw491_32\bin.TBB compilationDownload tbb43_20141204oss_src.tgz and unzip it under C:\Bin. You will have following directory tree: C:\Bin\tbb43_20141204oss. When you unzip the tgz file another single file without extension named tbb43_20141204oss_src will be created. If you open it will the zip program (I used 7zip) it will be seen as an archive and you can unzip it properly. Inside the root directory, a file named Makefile is contained (in case you downloaded the binaries it will be not present).We will now proceed to compile it. Open a command shell and issue the following command:C:\Bin\tbb43_20141204oss>mingw32-make compiler=gccDLL’s, i.e. tbb.dll, will be created in the build directory: C:\Bin\tbb43_20141204oss\build. We are interested in the C:\Bin\tbb43_20141204oss\build\windows_ia32_gcc_mingw4.9.1_release ones so we will now add this string to the PATH variable.VTK compilationleft200591Download VTK-6.1.0.zip and unzip it under C:\Bin. You will have following directory tree: C:\Bin\VTK-6.1.0. Before start compiling we need to patch a couple of files according to: patch is reported here.diff -ur VTK6.0.0.rc3/IO/Video/vtkWin32VideoSource.cxx VTK6.0.0.rc3.new/IO/Video/vtkWin32VideoSource.cxx--- VTK6.0.0.rc3/IO/Video/vtkWin32VideoSource.cxx2013-06-13 05:47:10.000000000 +1000+++ VTK6.0.0.rc3.new/IO/Video/vtkWin32VideoSource.cxx2013-06-22 16:06:01.000000000 +1000@@ -274,7 +274,7 @@ } // set the user data to 'this'- vtkSetWindowLong(this->Internal->ParentWnd,vtkGWL_USERDATA,(vtkLONG)this);+ vtkSetWindowLong(this->Internal->ParentWnd,vtkGWL_USERDATA,(intptr_t)this); // Create the capture window this->Internal->CapWnd = capCreateCaptureWindow("Capture",@@ -339,7 +339,7 @@ } // set user data for callbacks- if (!capSetUserData(this->Internal->CapWnd,(long)this))+ if (!capSetUserData(this->Internal->CapWnd,(intptr_t)this)) { vtkErrorMacro(<< "Initialize: couldn't set user data for callback"\ << " (" << GetLastError() << ")");Inside vtkConfigure.h file (generate after using CMake, in this example you can find it in C:\Bin\VTK-6.1.0\build\mingw_4.9.1_32bit_release\Common\Core) change:?#define VTK_USE_WIN32_THREADS?with?#define VTK_USE_PTHREADS?We will now proceed to compile it.Start CMake GUI, under Options menu suppress dev-warnings, and select:Where is the source code: C:\Bin\VTK-6.1.0Where to build the binaries: C:\Bin\VTK-6.1.0\build\mingw_4.9.1_32bit_release.Press Configure and let the process complete.Select Advanced.Now change following entries:CMAKE_BUILD_TYPE set to ReleaseSelect BUILD_EXAMPLESSelect Qt related entries:Module_vtkGUISupportQtModule_vtkGUISupportQtOpenGLModule_vtkRenderingQtModule_vtkViewsQtVTK_Group_QtSelect also:VTK_Group_ImagingDo not worry for entry CMAKE_SH saying CMAKE_SH-NOTFOUND, it has to be that way.Press Configure again. You will get an error, now you have to change a couple of entries:QT_QMAKE_EXECUTABLE, set it to the proper path, in this example C:\Bin\Qt\Qt5.4.0\5.4\mingw491_32\bin\qmake.exeVTK_QT_VERSION, change it to 5Add a PATH variable named CMAKE_PREFIX_PATH with value c:\Bin\Qt\Qt5.4.0\5.4\mingw491_32\lib\cmakePress Configure again. You will obtain some error and/or red line. Resolve them enabling or setting stuff properly. Should be quite easy, just a matter to resolve some missing module and set some Qt related path. In my case I had to add:Module_vtkTestingCoreModule_vtkTestingRenderingWhen, after a last configuration (you may need to repeat the configuration some time), all is fine you need to press Generate and wait until finished. Exit CMake.Go to correct file vtkConfigure.h as per above.Open a command prompt (with administrator privileges for the install) in C:\Bin\VTK-6.1.0\build\mingw_4.9.1_32bit_release.Give the command:C:\Bin\VTK-6.1.0\build\mingw_4.9.1_32bit_release>mingw32-makeand, when finished (will take long time) issue:C:\Bin\VTK-6.1.0\build\mingw_4.9.1_32bit_release>mingw32-make installWe now add the binary directory, containing executables, to the PATH variable: C:\Bin\VTK-6.1.0\build\mingw_4.9.1_32bit_release\bin.VTK is now installed on your machine and it is compiled with the proper MinGW toolchain.OpenCV installation and compilationDownload opencv-2.4.10.exe and execute it. Install it under C:\Bin. You will have following directory tree: C:\Bin\opencv-2.4.10\build.We will now proceed to compile it.Start CMake GUI, under Options menu suppress dev-warnings, and select (I stick to the directories used for this guide but they could be changed). I avoid to enable/change all options in one shot to describe what happen in each step and what need to be fixed.Step-by-step procedure (at the end the CMake report is provided and in a separate chapter all changed value are reported also for reference):Where is the source code: C:/Bin/OpenCV-2.4.10/opencv/sourcesWhere to build the binaries: C:/Bin/OpenCV-2.4.10/opencv/build/mingw_4.9.1_32bit_debug.This directory has been created for this purpose by us.Select WITH_TBB option. Not BUILD_TBB (leave this unchanged), this one will try to download and build TBB but we already did in previous step.Press Configure.A red line will appear named TBB_INCLUDE_DIRS, set it to C:/Bin/tbb43_20141204oss/include and press Configure again.Now you will have 2 red lines:TBB_STDDEF_PATH, that shall be correctly set to C:/Bin/tbb43_20141204oss/include/tbb/tbb_stddef.h, if not set it properly.TBB_LIB_DIR, that shall be incorrectly set, modify it to be C:/Bin/tbb43_20141204oss/build/windows_ia32_gcc_mingw4.9.1_release. Press Configure again.Set CMAKE_CONFIGURATION_TYPE to Debug or, if you prefer, to Release and generate only release version.Press Configure again.Now set WITH_QT and press Configure.An error is generated and many red rows shall appear. We’re going to fix them:Create a new PATH variable named CMAKE_PREFIX_PATH and assign to it the value C:/Bin/Qt/Qt5.4.0/5.4/mingw491_32/lib/cmake.Set QT_QMAKE_EXECUTABLE to C:/Bin/Qt/Qt5.4.0/5.4/mingw491_32/bin/qmake.exe if it is not set.Press Configure (you need to do it twice, until no red rows appears). In case some red row remains, resolve it pointing to the correct path.Select WITH_OPENGL and press Configure. Again, a couple of times until no red rows are present.Select BUILD_EXAMPLES, INSTALL_TESTS and INSTALL_C_EXAMPLES and press Configure.Select WITH_VTK and press Configure. Again, a couple of times until no red rows are present.De-select ENABLE_PRECOMPILED_HEADERS to avoid a gorgeous hard drive space used for the compilation.Press Configure and verify all it is fine.Enable BUILD_DOCS entry.Now create a new PATH entry named JAVA_HOME and set it to C:/Bin/Java/jdk1.7.0_80. Press Configure and all JAVA related entries shall be properly set.Press Configure twice, with BUILD_opencv_python entry selected.Press Generate.Check the CMake output that must be very similar to the one here below, pay attention to red lines, they must be correctly set:Detected version of GNU GCC: 49 (409)CUDA compilation is disabled (due to only Visual Studio compiler supported on your platform).Found Sphinx 1.2.3: C:/Bin/Anaconda/Scripts/sphinx-build.exeFound VTK ver. 6.1.0 (usefile: C:/Bin/VTK-6.1.0/CMake/UseVTK.cmake)General configuration for OpenCV 2.4.10 =====================================Version control: unknownPlatform:Host: Windows 6.2 AMD64CMake: 3.1.0CMake generator: MinGW MakefilesCMake build tool: C:/Bin/Qt/Qt5.4.0/Tools/mingw491_32/bin/mingw32-make.exeConfiguration: DebugC/C++:Built as dynamic libs?: YESC++ Compiler: C:/Bin/Qt/Qt5.4.0/Tools/mingw491_32/bin/g++.exe (ver 4.9.1)C++ flags (Release): -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -O2 -DNDEBUG -DNDEBUGC++ flags (Debug): -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -g -O0 -DDEBUG -D_DEBUGC Compiler: C:/Bin/Qt/Qt5.4.0/Tools/mingw491_32/bin/gcc.exeC flags (Release): -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -O2 -DNDEBUG -DNDEBUGC flags (Debug): -fsigned-char -mstackrealign -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -fdiagnostics-show-option -fomit-frame-pointer -msse -msse2 -mfpmath=sse -ffunction-sections -g -O0 -DDEBUG -D_DEBUGLinker flags (Release): Linker flags (Debug): Precompiled headers: NOOpenCV modules:To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab vizDisabled: worldDisabled by dependency: -Unavailable: androidcamera dynamicuda java pythonWindows RT support: NOGUI: QT 5.x: YES (ver 5.4.0)QT OpenGL support: YES (Qt5::OpenGL 5.4.0)OpenGL support: YES (glu32 opengl32)VTK support: YES (ver 6.1.0)Media I/O: ZLib: build (ver 1.2.7)JPEG: build (ver 62)PNG: build (ver 1.5.12)TIFF: build (ver 42 - 4.0.2)JPEG 2000: build (ver 1.900.1)OpenEXR: build (ver 1.7.1)Video I/O:Video for Windows: YESDC1394 1.x: NODC1394 2.x: NOFFMPEG: YES (prebuilt binaries)codec: YES (ver 55.18.102)format: YES (ver 55.12.100)util: YES (ver 52.38.100)swscale: YES (ver 2.3.100)gentoo-style: YESOpenNI: NOOpenNI PrimeSensor Modules: NOPvAPI: NOGigEVisionSDK: NODirectShow: YESMedia Foundation: NOXIMEA: NOIntel PerC: NOOther third-party libraries:Use IPP: NOUse Eigen: NOUse TBB: YES (ver 4.3 interface 8002)Use OpenMP: NOUse GCD NOUse Concurrency NOUse C=: NOUse Cuda: NOUse OpenCL: YESOpenCL:Version: dynamicInclude path: C:/Bin/OpenCV-2.4.10/opencv/sources/3rdparty/include/opencl/1.2Use AMD FFT: NOUse AMD BLAS: NOPython:Interpreter: C:/Bin/Anaconda/python.exe (ver 2.7.8)Libraries: C:/Bin/Anaconda/libs/python27.lib (ver 2.7.8)numpy: C:/Bin/Anaconda/lib/site-packages/numpy/core/include (ver 1.9.0)packages path: C:/Bin/Anaconda/Lib/site-packagesJava:ant: NOJNI: C:/Bin/Java/jdk1.7.0_80/include C:/Bin/Java/jdk1.7.0_80/include/win32 C:/Bin/Java/jdk1.7.0_80/includeJava tests: NODocumentation:Build Documentation: YESSphinx: C:/Bin/Anaconda/Scripts/sphinx-build.exe (ver 1.2.3)PdfLaTeX compiler: C:/Bin/MiKTeX2.9/miktex/bin/pdflatex.exeTests and samples:Tests: YESPerformance tests: YESC/C++ Examples: YESInstall path: C:/Bin/OpenCV-2.4.10/opencv/build/mingw_4.9.1_32bit_debug/installcvconfig.h is in: C:/Bin/OpenCV-2.4.10/opencv/build/mingw_4.9.1_32bit_debug-----------------------------------------------------------------Configuring doneGenerating doneWe are ready to compile now!Open a command prompt with administrator privileges and run from the build directory:mingw32-make and after a while, when complete and if successfully:mingw32-make install.left15360You now need to repeat all the steps for the release version. Just do it in directory C:\Bin\OpenCV-2.4.10\opencv\build\mingw_4.9.1_32bit_release.You could duplicate the debug one to save time in creating the CMake stuff but in that case be careful to check that all installation path are now pointing to the *release directory (you need to manually modify some CMake entry visible if advanced flag is selected).We will then create an environmental variable OPENCV_DIR with value C:\Bin\OpenCV-2.4.10\opencv\build.We also add the binary directory, containing executables, to the PATH variable: C:\Bin\OpenCV-2.4.10\opencv\build\mingw_4.9.1_32bit_debug\bin.Post-checksCMake changed values for OpenCV release compilationCommandline options:-DPYTHON_INCLUDE_DIR:PATH="C:/Bin/Anaconda/include" -DTBB_LIB_DIR:PATH="C:/Bin/tbb43_20141204oss/build/windows_ia32_gcc_mingw4.9.1_release" -DANT_EXECUTABLE:FILEPATH="ANT_EXECUTABLE-NOTFOUND" -DCMAKE_INSTALL_PREFIX:PATH="C:/Bin/OpenCV-2.4.10/opencv/build/mingw_4.9.1_32bit_release/install" -DWITH_QT:BOOL="1" -DWITH_OPENGL:BOOL="1" -DINSTALL_TESTS:BOOL="1" -DBUILD_EXAMPLES:BOOL="1" -DPYTHON_EXECUTABLE:FILEPATH="C:/Bin/Anaconda/python.exe" -DCMAKE_PREFIX_PATH:PATH="C:/Bin/Qt/Qt5.4.0/5.4/mingw491_32/lib/cmake" -DPYTHON_LIBRARY:FILEPATH="C:/Bin/Anaconda/libs/python27.lib" -DTBB_INCLUDE_DIRS:PATH="C:/Bin/tbb43_20141204oss/include" -DQT_QMAKE_EXECUTABLE:FILEPATH="C:/Bin/Qt/Qt5.4.0/5.4/mingw491_32/bin/qmake.exe " -DWITH_VTK:BOOL="1" -DCMAKE_BUILD_TYPE:STRING="Release" -DPYTHON_NUMPY_INCLUDE_DIR:PATH="C:/Bin/Anaconda/lib/site-packages/numpy/core/include" -DINSTALL_PYTHON_EXAMPLES:BOOL="1" -DENABLE_PRECOMPILED_HEADERS:BOOL="0" -DWITH_TBB:BOOL="1" -DINSTALL_C_EXAMPLES:BOOL="1" -DPYTHON_LIBRARY_RELEASE:FILEPATH="C:/Bin/Anaconda/libs/python27.lib" Cache file:PYTHON_INCLUDE_DIR:PATH=C:/Bin/Anaconda/includeTBB_LIB_DIR:PATH=C:/Bin/tbb43_20141204oss/build/windows_ia32_gcc_mingw4.9.1_releaseANT_EXECUTABLE:FILEPATH=ANT_EXECUTABLE-NOTFOUNDCMAKE_INSTALL_PREFIX:PATH=C:/Bin/OpenCV-2.4.10/opencv/build/mingw_4.9.1_32bit_release/installWITH_QT:BOOL=1WITH_OPENGL:BOOL=1INSTALL_TESTS:BOOL=1BUILD_EXAMPLES:BOOL=1PYTHON_EXECUTABLE:FILEPATH=C:/Bin/Anaconda/python.exeCMAKE_PREFIX_PATH:PATH=C:/Bin/Qt/Qt5.4.0/5.4/mingw491_32/lib/cmakePYTHON_LIBRARY:FILEPATH=C:/Bin/Anaconda/libs/python27.libTBB_INCLUDE_DIRS:PATH=C:/Bin/tbb43_20141204oss/includeQT_QMAKE_EXECUTABLE:FILEPATH=C:/Bin/Qt/Qt5.4.0/5.4/mingw491_32/bin/qmake.exe WITH_VTK:BOOL=1CMAKE_BUILD_TYPE:STRING=ReleasePYTHON_NUMPY_INCLUDE_DIR:PATH=C:/Bin/Anaconda/lib/site-packages/numpy/core/includeENABLE_PRECOMPILED_HEADERS:BOOL=0WITH_TBB:BOOL=1INSTALL_C_EXAMPLES:BOOL=1PYTHON_LIBRARY_RELEASE:FILEPATH=C:/Bin/Anaconda/libs/python27.libEnvironmental variablesModified or created variables are reported here in order to allow crosschecking them.OPENCV_DIR (dlls location)C:\Bin\OpenCV-2.4.10\opencv\buildTBB_DIR (location of tbb.dll)C:\Bin\tbb43_20141204oss\build\windows_ia32_gcc_mingw4.9.1_releasePATH (on a single line, paths are reported here one per line for convenience)C:\Bin\Anaconda;C:\Bin\Anaconda\Scripts; C:\Bin\VTK-6.1.0\build\mingw_4.9.1_32bit_release\bin;C:\Bin\tbb43_20141204oss\build\windows_ia32_gcc_mingw4.9.1_release; C:\Bin\CMake\bin;C:\Bin\MiKTeX2.9\miktex\bin; C:\Bin\Qt\Qt5.4.0\Tools\mingw491_32\bin; …An example projectYou can then download the project for Qt5 I have prepare and run it. You need to have a camera attached to the PC. Check carefully the project file and adjust paths accordingly if it is necessary. If you just used my ones, it shall run straightforward.Side projectsRaspberry OpenCV + QtThis installation of OpenCV, with more or less same options, has been done also for a Linux Ubuntu 64 bit machine (Virtual Machine) and on Raspberry PI B+ model; the latter driving decision to enable Qt option, in order to have the same Qt5 project working on all machines.Haar Cascades trainingThe TBB option under Windows has been adopted for faster Haar Cascades development. I am currently working on training a different set of Haar Cascades to recognize particular objects (on the net it is easy to find Haar Cascades for human body parts but not so easy for different objects). ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download