OpenCV 3.4.1 on Cygwin 2.9.0 environment

>> Japanese page
>> version 2.4.12.2

twitter ID: @cygopencv


my built libraries for 64bit Cygwin:
opencv-3.4.1-cygwin64-g++-6.4.0-shared-release-20180228.tar.bz2

output of "opencv_version.exe -v"


1) preparation #1
Install required packages using Cygwin's setup.exe.
In my opinion, the following packages (and their depending packages) are our minimal needed packages:

  "cmake"
  "gcc-g++"
  "make"
  "diffutils"
  "patch"
  "libwebp-devel"
  "libIlmImf-devel"
  "libjasper-devel"
  "libjpeg-devel"
  "libpng-devel"
  "libtiff-devel"
  "libhdf5-devel"
  "libbz2-devel"
  "zlib-devel"


2) preparation #2 (recommended)
Build ffmpeg.

for example:

  $ cd /tmp/
  $ tar xvjf ffmpeg-3.4.2.tar.bz2
  $ cd ffmpeg-3.4.2/
  $ ./configure --disable-yasm \
                --disable-iconv \
                --enable-avresample \
                --prefix=/usr/local/ffmpeg-3.4.2/
  $ make -j ${NUMBER_OF_PROCESSORS} install


3-1) preparation #3.1 (optional: for viz module)
OpenCV "viz" module requires VTK. So, build VTK by following my instruction page.


3-2) preparation #3.2 (optional: for sfm module)
OpenCV "sfm" module requires ceres-solver for reconstruction process. If you do not have ceres-solver, the reconstruction funcionality will be disabled. Even in such case, glog and gflags are needed to build sfm module.
To build ceres-solver, you need the following Cygwin packages:

  "eigen3"
  "libsuitesparseconfig-devel"
  "libspqr-devel"
  "libmetis-devel"
  "libcxsparse-devel"
  "libcolamd-devel"
  "libcholmod-devel"
  "libccolamd-devel"
  "libcamd-devel"
  "libamd-devel"
Then, build gflags, glog, and ceres-solver .
for example:
  $ cd /tmp/
  $ tar xvzf gflags-2.2.1.tar.gz
  $ mkdir gflags_build
  $ cd gflags_build/
  $ cmake -D CMAKE_INSTALL_PREFIX:PATH=/usr/local/gflags-2.2.1/ \
          /tmp/gflags-2.2.1/
  $ make -j ${NUMBER_OF_PROCESSORS} install

  $ cd /tmp/
  $ tar xvzf glog-0.3.5.tar.gz
  $ cd glog-0.3.5/
  $ env CPPFLAGS="-D__CYGWIN64__" \
       ./configure --with-gflags=/usr/local/gflags-2.2.1/ \
                   --prefix=/usr/local/glog-0.3.5/
  $ make -j ${NUMBER_OF_PROCESSORS} install

  $ cd /tmp/
  $ tar xvzf ceres-solver-1.13.0.tar.gz
  $ mkdir ceres-solver_build
  $ cd ceres-solver_build/
  $ cmake -D CXSPARSE_INCLUDE_DIR:PATH=/usr/include/suitesparse/ \
          -D GFLAGS_INCLUDE_DIR_HINTS:PATH=/usr/local/gflags-2.2.1/include/ \
          -D GFLAGS_LIBRARY_DIR_HINTS:PATH=/usr/local/gflags-2.2.1/lib/ \
          -D GLOG_INCLUDE_DIR:PATH=/usr/local/glog-0.3.5/include/ \
          -D GLOG_LIBRARY:PATH=/usr/local/glog-0.3.5/lib/libglog.a \
          -D CMAKE_INSTALL_PREFIX:PATH=/usr/local/ceres-solver-1.13.0/ \
          /tmp/ceres-solver-1.13.0/
  $ make -j ${NUMBER_OF_PROCESSORS} install


3-3) preparation #3.3 (optional: for text module)
OpenCV "text" module has interface to Tesseract-OCR. You can install Tesseract-OCR library by a Cygwin package:

  "tesseract-ocr-devel"


3-4) preparation #3.4 (optional: for freetype module)
OpenCV "freetype" module requires freetype library and HarfBuzz. You can install freetype library by a Cygwin package:

  "libfreetype-devel"
You must build HarfBuzz by yourself. You can get the tarball codes from here. (Do not to try downloading the code from github. The github codes do not include build-configuration files.) Please note to use configure (not cmake command), because HarfBuzz does no provide *.cmake files.
for example:
  $ cd /tmp/
  $ tar xvzf harfbuzz-1.7.5.tar.bz2
  $ cd harfbuzz-1.7.5/
  $ ./configure --enable-static \
                --disable-shared \
                --prefix=/usr/local/harfbuzz-1.7.5/
  $ make -j ${NUMBER_OF_PROCESSORS} install


4) apply patch
Get opencv-3.4.1.tar.gz and opencv_contrib-3.4.1.tar.gz, and apply my Cygwin patches: opencv-3.4.1-cygwin-patch-20180228.txt.gz and opencv_contrib-3.4.1-cygwin-patch-20180228.txt.gz.

for example:

  $ cd /tmp/
  $ tar xvzf opencv-3.4.1.tar.gz
  $ gunzip opencv-3.4.1-cygwin-patch-20180228.txt.gz
  $ cd opencv-3.4.1/
  $ patch -p1 < ../opencv-3.4.1-cygwin-patch-20180228.txt

  $ cd /tmp/
  $ tar xvzf opencv_contrib-3.4.1.tar.gz
  $ gunzip opencv_contrib-3.4.1-cygwin-patch-20180228.txt.gz
  $ cd opencv_contrib-3.4.1/
  $ patch -p1 < ../opencv_contrib-3.4.1-cygwin-patch-20180228.txt


5) build and install
To build OpenCV, you must disable ENABLE_CXX11 and HAVE_CXX11 in cmake, and set an option "-std=gnu++14" to g++ compiler. You also need to disable WITH_ITT. (I could not succsessfuly link OpenCV core module with ITT.) Additionally, setting of CPU_DISPATCH was needed (otherwise, AVX512_SKX setting caused some error).
for example:

  $ mkdir build_shared_release/
  $ cd build_shared_release/
  $ env PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:/usr/local/ffmpeg-3.4.2/lib/pkgconfig/:/usr/local/harfbuzz-1.7.5/lib/pkgconfig/" \
    cmake -D CMAKE_BUILD_TYPE:STRING=RELEASE \
          -D BUILD_SHARED_LIBS:BOOL=ON \
          -D ENABLE_CXX11:BOOL=OFF \
          -D HAVE_CXX11:BOOL=OFF \
          -D CMAKE_CXX_FLAGS:STRING="-std=gnu++14 -Wa,-mbig-obj" \
          -D CMAKE_C_FLAGS:STRING="-Wa,-mbig-obj" \
          -D CPU_DISPATCH:STRING="SSE4_1;SSE4_2;AVX;FP16;AVX2;" \
          -D WITH_ITT:BOOL=OFF \
          -D WITH_IPP:BOOL=OFF \
          -D WITH_OPENMP:BOOL=ON \
          -D WITH_OPENGL:BOOL=ON \
          -D ENABLE_FAST_MATH:BOOL=ON \
          -D BUILD_PERF_TESTS:BOOL=OFF \
          -D BUILD_TESTS:BOOL=OFF \
          -D BUILD_EXAMPLES:BOOL=OFF \
          -D VTK_DIR:PATH=/usr/local/vtk-8.1.0/lib/cmake/vtk-8.1/ \
          -D GLOG_INCLUDE_DIR:PATH=/usr/local/glog-0.3.5/include/ \
          -D Glog_LIBS:PATH=/usr/local/glog-0.3.5/lib/libglog.a \
          -D GFLAGS_INCLUDE_DIRS:PATH=/usr/local/gflags-2.2.1/include/ \
          -D GFLAGS_LIBRARIES:PATH=/usr/local/gflags-2.2.1/lib/libgflags.a \
          -D Ceres_DIR:PATH=/usr/local/ceres-solver-1.13.0/lib/cmake/Ceres/ \
          -D CMAKE_INSTALL_PREFIX:PATH=/usr/local/opencv-3.4.1/ \
          -D OPENCV_EXTRA_MODULES_PATH:PATH=/tmp/opencv/opencv_contrib-3.4.1/modules/ \
          -D OPENCV_ENABLE_NONFREE:BOOL=ON \
          /tmp/opencv-3.4.1/
  $ make -j ${NUMBER_OF_PROCESSORS} install