系統環境:
win7 64、mingw、cmake3.9.2、opencv3.3
安裝配置mingw和cmake后,查看結果
D:\opencv3.3\sources>cmake -version cmake version 3.9.2 CMake suite maintained and supported by Kitware (kitware.com/cmake). D:\opencv3.3\sources>make -v GNU Make 3.82.90 Built for i686-pc-mingw32 Copyright (C) 1988-2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
步驟:
1.下載https://github.com/opencv/opencv
2.下載https://github.com/opencv/opencv_contrib
3.輸入命令cmake-gui,分別選擇源碼目錄和編譯文件存放目錄,如圖:

4.點擊下方configure按鈕,看到configuring done說明配置成功
5.找到BUILD,選擇opencv_contrib/modules存放目錄,如圖,

6.重復步驟4
7.點擊Generate按鈕,看到Generate Done,至此cmake完成。
8.cd進入mybuild目錄,執行make -j4
9.坐等build 100%
10.執行make install
大功告成。
遇到問題:
C:\MinGW\bin\windres.exe: unknown option -- W
...
v:\MinGW-Builds\mingw64\bin\windres.exe: supported targets: pe-x86-64 pei-x86-64 pe-bigobj-x86-64 elf64-x86-64 elf64-l1om elf64-k1om pe-i386 pei-i386 elf32-i386 elf32-iamcu elf64-little elf64-big elf32-little elf32-big plugin srec symbolsrec verilog tekhex binary ihex modules/core/CMakeFiles/opencv_core.dir/build.make:1642: recipe for target `modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj' failed make[2]: *** [modules/core/CMakeFiles/opencv_core.dir/vs_version.rc.obj] Error 1 CMakeFiles/Makefile2:1512: recipe for target `modules/core/CMakeFiles/opencv_core.dir/all' failed make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2 Makefile:162: recipe for target `all' failed make: *** [all] Error 2
經查明是cmake-3.9+版本的bug
解決方法:去掉ENABLE_PRECOMPILED_HEADERS再make如圖:

補充:cmake-gui Configure、Generate均是為真正編譯make做准備工作。也可以通過cmake -G "MinGW Makefiles".進行配置。
