Configuring CMake to build OpenCV on Windows

General procedure

  1. Start the GUI version of CMake (cmake-gui).

  2. Select the folder C:\OpenCV\sources as the source directory.

  3. Select the folder C:\OpenCV\builds as the build directory.

  4. Enable the Grouped and Advanced checkboxes just below the build directory name. These will impact the way the packages information will be displayed in the CMake GUI in the following steps.

    CMake sources builds
  5. Press the “Configure” button. A window pops up, letting you specify the compiler (and IDE) you want to use. Pick Visual Studio 10, 32-bit or 64-bit according to your Matlab version. Select also “Use default native compilers” and click Finish.

    CMake select generator

    Note

    In case you would like to redo all the steps from the beginning (if you made a mistake somewhere, for instance), you can clear CMake cache in the menu option “File > Delete Cache”.

  6. 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).

  7. Configure CMake until all the elements are found. Follow the instructions below.

    Note

    If you don’t need it, you might want to deactivate the Python module both in 32-bit and 64-bit versions since it might not build correctly.

  8. Once you are comfortable with your CMake configuration, press Generate and close CMake.

Here is an alternate version of those instructions, but it does not goes as deep in the details as this tutorial: http://seevisionc.blogspot.co.uk/2014/03/compiling-opencv-30-with-matlab-support.html.

Configuration details

BUILD group

Activate everything except:

  • BUILD_CUDA_STUBS
  • BUILD_DOCS
  • BUILD_OPENEXR
  • BUILD_TBB
  • BUILD_WITH_DYNAMIC_IPP
  • BUILD_opencv_apps
  • BUILD_opencv_python2
  • BUILD_opencv_python3
  • BUILD_opencv_ts
  • BUILD_opencv_world

Note

For more info about what each OpenCV module does, please visit http://docs.opencv.org/.

Note

To build the doc, Doxygen must be installed. This is why I disabled it, because the doc is easily accessible online anyway.

Note

The Python interface does not build properly on my machine, this is why I have disabled both items about Python. However, feel free to enable the one corresponding to your Python installation (python2 or python3).

ENABLE group

Make sure to check ENABLE_SOLUTION_FOLDERS.

INSTALL group

Check INSTALL_C_EXAMPLES and INSTALL_TESTS.

MATLAB group

Make sure every field is populated here (should be the case automatically).

OPENCV group

Complete the entry OPENCV_EXTRA_MODULES_PATH with the path to the extra modules: C:\OpenCV\contrib\modules.

WITH group

Activate the following items (15 in total):

  • WITH_DIRECTX
  • WITH_DSHOW
  • WITH_EIGEN
  • WITH_FFMPEG
  • WITH_IPP
  • WITH_JASPER
  • WITH_JPEG
  • WITH_OPENCL
  • WITH_OPENCLAMDBLAS
  • WITH_OPENCLAMDFFT
  • WITH_PNG
  • WITH_TBB
  • WITH_TIFF
  • WITH_VFW
  • WITH_WIN32UI

Intel TBB

Here are instructions adapted from http://stackoverflow.com/questions/16767464/how-to-install-opencv-with-tbb-enabled-using-mingw.

  1. From CMake, configure one time OpenCV (should already be done).

  2. Enable “WITH_TBB”.

    Note

    Be careful NOT enabling BUILD_TBB: the automatic downloading and building of OpenCV failed miserably for me despite many efforts. If you had previously enabled BUILD_TBB, my suggestion is to restart from the beginnning, clearing cmake cache.

  3. Configure a second time OpenCV.

  4. Then a new group should appear (in red), named “Ungrouped Entries”. If the TBB include directory is not found, this group will have the option “TBB_INCLUDE_DIRS” with the value “TBB_INCLUDE_DIRS-NOTFOUND”.

  5. Click on the value and then on the tiny button ”...” appearing on the right-side of the field. Provide the path to the TBB headers, which should be C:\OpenCV\tbb\include.

  6. When done, press the “Configure” button again.

  7. Now, CMake should have been able to locate the TBB headers (include dir). Therefore, a new group “TBB” should appear in the interface. If it is not the case, then retry to locate the TBB headers. They should lie in some include directory within the tbb folder.

  8. In the “TBB” group, there are two new variables whose default values are correct. Note that the value of TBB_LIB_DIR depends on your compiler.

  9. The “TBB” group is now complete. Here are the three variables it contains with their values:

    • TBB_INCLUDE_DIRS: C:\OpenCV\tbb\include
    • TBB_LIB_DIR: C:\OpenCV\tbb\lib\intel64\vc10
    • TBB_STDDEF_PATH: C:\OpenCV\tbb\include\tbb\tbb_stddef.h