Build and install OpenCV on Windows

Build OpenCV with Extra module, Eigen, Qt, TBB, VTK, XIMEA enabled. The path etc. will differ depending on the version, so please read as appropriate. The environment implemented this time is as follows.

environment

OpenCV build

Preparation

Install Python & NumPy

  1. Download Python 2.7 series and Python 3 series from Official Site. Install directly under the C drive.
  2. Download NumPy for your environment from here. Install both Python2.7 and 3 with pip install ~ .whl.

Software installation

  1. Visual Studio, CMake Installation.

Source download

  1. Download the source of opencv and opencv_contrib from GitHub. Expand to C: \ opencv and C: \ opencv \ dev \ opencv_contrib respectively.

  2. Download the latest stable release of Eigen. Expand to C: \ opencv \ dev \ eigen.

  3. Install Qt. In the component selection, select and install only Qt> Qt 5.8> msvc2015 64-bit.

  4. Download the Latest release of Intel® TBB. Expand to C: \ opencv \ dev \ tbb \ bin \ intel64 \ vc14.

  5. Download the source of VTK. Expand to C: \ VTK. Start CMake with administrator privileges and configure as sourceC: \ VTK, buildC: \ VTK \ build. Click Generate → Open Project to open the project in Visual Studio. If you build "ALL_BUILD" and "INSTALL" respectively, VTK will be installed in C: \ Program Files.

  6. Install XIMEA Windows Software Package.

  7. Pass the path as follows.

    Set the path of environment variables
    C:\opencv
    C:\opencv\dev\eigen
    C:\opencv\dev\tbb\bin\intel64\vc14
    C:\XIMEA\API\x64
    C:\Qt\5.8\msvc2015_64\bin
    C:\Program Files\VTK
    C:\Program Files\VTK\bin

Build

  1. Start CMake. Click Configure as sourceC: \ opencv, buildC: \ opencv \ build.

  2. Press Configure several times until the following settings are complete to eliminate the red item.

    Check the following
    WITH_EIGEN
    WITH_OPENGL
    WITH_QT
    WITH_TBB
    WITH_VTK
    WITH_XIMEA
    Uncheck below
    WITH_CUDA
    WITH_CUFFT
    Name Value
    OPENCV_EXTRA_MODULES_PATH C:/opencv/dev/opencv_contrib/modules
    EIGEN_INCLDE_PATH C:/opencv/dev/eigen
    QT_QMAKE_EXECUTSBLE C:/Qt/5.8/msvc2015_64/bin/qmake.exe
    Qt5Concurrent_DIR C:/Qt/5.8/msvc2015_64/lib/cmake/Qt5Concurrent
    Qt5Core_DIR C:/Qt/5.8/msvc2015_64/lib/cmake/Qt5Core
    Qt5Gui_DIR C:/Qt/5.8/msvc2015_64/lib/cmake/Qt5Gui
    Qt5OpenGL_DIR C:/Qt/5.8/msvc2015_64/lib/cmake/Qt5OpenGL
    Qt5Test_DIR C:/Qt/5.8/msvc2015_64/lib/cmake/Qt5Test
    Qt5Widgets_DIR C:/Qt/5.8/msvc2015_64/lib/cmake/Qt5Widgets
    TBB_ENV_INCLDE C:/opencv/dev/tbb/include
    TBB_ENV_LIB C:/opencv/dev/tbb/lib/intel64/vc14/tbb.lib
    TBB_ENV_LIB_DEBUG C:/opencv/dev/tbb/lib/intel64/vc14/tbb_debug.lib
    TBB_VER_FILE C:/opencv/dev/tbb/include/tbb/tbb_stddef.h
  3. If there is no red item, click Generate → Open Project. Open the project in Visual Studio.

  4. When the project is opened in Visual Studio, set the configuration Release and platform x64, right-click "ALL_BUILD" → build. If there are no errors, right-click "INSTALL" → build.

  5. "cv2.pyd" and "cv2.cp35-win_amd64.pyd" can be created in C: \ Python27 \ Lib \ site-packages and C: \ Python35 \ Lib \ site-packages, respectively.

  6. Pass the path to C: \ opencv, C: \ opencv \ build \ install \ bin.

When you get an error in stringutils.cpp

Commenting out the following three lines works fine.

stringutils.cpp


	static std::map<QString, QString> replacements3 = { { "EV", "AF" },
		                                            //{ "Ü", "A" },
		                                            //{ "Ö", "A" },
		                                            //{ "Ä", "A" },
		                                            { "O", "G" },
		                                            { "Z", "S" },
		                                            { "M", "N" },
		                                            { "KN", "N" },
		                                            { "K", "C" },
		                                            { "SCH", "SSS" },
		                                            { "PH", "FF" } };

Verification

import cv2
print(cv2.getBuildInformation())
General configuration for OpenCV 3.2.0-dev =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            C:/opencv/dev/opencv_contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2017-06-08T23:48:41Z
    Host:                        Windows 10.0.14393 AMD64
    CMake:                       3.8.1
    CMake generator:             Visual Studio 14 2015 Win64
    CMake build tool:            C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
    MSVC:                        1900

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3
      requested:                 SSSE3
    Dispatched code generation:  SSE4_1 FP16 AVX AVX2
      requested:                 SSE4_1 AVX FP16 AVX2
      SSE4_1 (0 files):          + SSE4_1
      FP16 (1 files):            + SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (1 files):             + SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (1 files):            + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe  (ver 19.0.24215.1)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi       /wd4251 /wd4324 /wd4275 /wd4589 /MP8  /MD /O2 /Ob2 /DNDEBUG  /Zi
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi       /wd4251 /wd4324 /wd4275 /wd4589 /MP8  /MDd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi         /MP8  /MD /O2 /Ob2 /DNDEBUG  /Zi
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi         /MP8  /MDd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release):      /machine:x64  /INCREMENTAL:NO  /debug
    Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL 
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          comctl32 gdi32 ole32 setupapi ws2_32 Qt5::Test Qt5::Concurrent Qt5::OpenGL vfw32 xiapi64 vtkRenderingOpenGL2 vtkCommonCore vtksys vtkCommonDataModel vtkCommonMath vtkCommonMisc vtkCommonSystem vtkCommonTransforms vtkCommonExecutionModel vtkIOImage vtkDICOMParser vtkmetaio vtkzlib vtkjpeg vtkpng vtktiff vtkImagingCore vtkRenderingCore vtkCommonColor vtkCommonComputationalGeometry vtkFiltersCore vtkFiltersGeneral vtkFiltersGeometry vtkFiltersSources vtkglew vtkInteractionStyle vtkFiltersExtraction vtkFiltersStatistics vtkImagingFourier vtkalglib vtkRenderingLOD vtkFiltersModeling vtkIOPLY vtkIOCore vtkFiltersTexture vtkRenderingFreeType vtkfreetype vtkIOExport vtkRenderingGL2PSOpenGL2 vtkgl2ps vtkIOGeometry vtkIOLegacy Qt5::Core Qt5::Gui Qt5::Widgets glu32 opengl32 C:/opencv/dev/tbb/lib/intel64/vc14/tbb.lib
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 core flann imgproc ml objdetect phase_unwrapping photo plot reg surface_matching video viz xphoto bgsegm dnn face fuzzy imgcodecs shape videoio xobjdetect highgui superres ts bioinspired dpm features2d line_descriptor saliency text calib3d ccalib cvv datasets rgbd stereo structured_light tracking videostab xfeatures2d ximgproc aruco optflow stitching python2 python3
    Disabled:                    world contrib_world
    Disabled by dependency:      -
    Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java cnn_3dobj dnn_modern freetype hdf matlab sfm

  Windows RT support:            NO

  GUI: 
    QT 5.x:                      YES (ver 5.8.0)
    QT OpenGL support:           YES (Qt5::OpenGL 5.8.0)
    OpenGL support:              YES (glu32 opengl32)
    VTK support:                 YES (ver 7.1.1)

  Media I/O: 
    ZLib:                        build (ver 1.2.8)
    JPEG:                        build (ver 90)
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         build (ver 1.6.24)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    GDAL:                        NO
    GDCM:                        NO

  Video I/O:
    Video for Windows:           YES
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (ver )
      avformat:                  YES (ver )
      avutil:                    YES (ver )
      swscale:                   YES (ver )
      avresample:                YES (ver )
    GStreamer:                   NO
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    OpenNI2:                     NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    DirectShow:                  YES
    Media Foundation:            NO
    XIMEA:                       YES
    Intel PerC:                  NO

  Parallel framework:            TBB (ver 2017.0 interface 9107)

  Other third-party libraries:
    Use Intel IPP:               2017.0.2 [2017.0.2]
               at:               C:/opencv/build/3rdparty/ippicv/ippicv_win
    Use Intel IPP IW:            prebuilt binaries (2017.0.2)
    Use Intel IPP Async:         NO
    Use Lapack:                  NO
    Use Eigen:                   YES (ver 3.3.3)
    Use Cuda:                    NO
    Use OpenCL:                  YES
    Use OpenVX:                  NO
    Use custom HAL:              NO

  OpenCL:                        <Dynamic loading of OpenCL library>
    Include path:                C:/opencv/3rdparty/include/opencl/1.2
    Use AMDFFT:                  NO
    Use AMDBLAS:                 NO

  Python 2:
    Interpreter:                 C:/Python27/python.exe (ver 2.7.13)
    Libraries:                   C:/Python27/libs/python27.lib (ver 2.7.13)
    numpy:                       C:/Python27/lib/site-packages/numpy/core/include (ver 1.12.1)
    packages path:               C:/Python27/Lib/site-packages

  Python 3:
    Interpreter:                 C:/Python35/python.exe (ver 3.5.3)
    Libraries:                   C:/Python35/libs/python35.lib (ver 3.5.3)
    numpy:                       C:/Python35/lib/site-packages/numpy/core/include (ver 1.12.1)
    packages path:               C:/Python35/Lib/site-packages

  Python (for build):            C:/Python27/python.exe

  Java:
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        Matlab not found or implicitly disabled

  Documentation:
    Doxygen:                     NO

  Tests and samples:
    Tests:                       YES
    Performance tests:           YES
    C/C++ Examples:              NO

  Install path:                  C:/opencv/build/install

  cvconfig.h is in:              C:/opencv/build
-----------------------------------------------------------------

Confirmation 2

import cv2
import numpy as np

im = cv2.imread("cat.png ")
cv2.imshow("cat",im)
cv2.waitKey(0)
cv2.destroyAllWindows()

cat.png

Recommended Posts

Build and install OpenCV on Windows
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Install OpenCV and Chainer on Ubuntu
Install easy_install and pip on windows
[UE4] Build DedicatedServer on Windows and Linux
Build Python3 and OpenCV environment on Ubuntu 18.04
Install wsl2 and master linux on windows
Install Anaconda on Windows 10
Install python on windows
Install pycuda on Windows10
Build TensorFlow on Windows
Build XGBoost on Windows
Install pygraphviz on Windows 10
Install Chainer 1.5.0 on Windows
Install and run Python3.5 + NumPy + SciPy on Windows 10
[Python] How to install OpenCV on Anaconda [Windows]
Install ZIP version Python and pip on Windows 10
Build Linux on a Windows environment. Steps to install Laradock and migrate
Install Numpy on virtualenv on Windows
Install watchdog on Windows + Python 3.3
Install Python and Flask (Windows 10)
Install Win-Kex (kali-linux) on Windows 10.
Install cvxpy on windows, Anaconda
Try using OpenCV on Windows
Build Python environment on Windows
Install OpenCV on Ubuntu + python
Install Chainer 1.6 (GPU) on Windows 7.
Build python environment on windows
[Python] [Chainer] [Windows] Install Chainer on Windows
Install OpenCV4 on Raspberry Pi 3
Install Python3 on Mac and build environment [Definitive Edition]
[Windows] [Python3] Install python3 and Jupyter Notebook (formerly ipython notebook) on Windows
Install LAMP on Amazon Linux 2 and build a WordPress environment.
Python 3.6 on Windows ... and to Xamarin.
Pip install --ugrade pip fails on Windows
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
(Windows10) Install Linux environment and gnuplot.
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Install python2.7 on windows 32bit environment
Install xgboost (python version) on Windows
Install Python on Windows + pip + virtualenv
Install Pytorch on Blender 2.90 python on Windows
How to install pycrypto on Windows
Integrate Modelica and Python on Windows
How to install OpenCV on Mac
Install python and Visual Studio Code on windows10 (April 2020 version)
Install fabric on Ubuntu and try
Mastering pip and wheel on windows
Install Python development environment on Windows 10
Install PyStan on Windows without Anaconda
How to install music 21 on windows
How to install OpenCV on Cloud9 and run it in Python
Build a 64-bit Python 2.7 environment with TDM-GCC and MinGW-w64 on Windows 7
Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
Notes for using OpenCV on Windows10 Python 3.8.3.
Install opencv on Mac using Anaconda Navigator
Python 2.7, 3.4, 3.5 extension module build environment on Windows
docker and PyCharm under proxy on windows
[Kivy] How to install Kivy on Windows [Python]
Install and launch k3s on Manjaro Linux