1. Prepare:
1.cmake-3.11.1-win64-x64 https://cmake.org/files/v3.11/ 2.qt-opensource-windows-x86-msvc2015-5.6.3 3.vs2015 4.opencv-3.4.1-vc14_vc15.exe https://github.com/opencv/opencv/releases/tag/3.4.1
2. Install software:
1.cmake installation (unzip to use)
2.qt installation, also install WDB http://www.codemachine.com/downloads.html if required
3.VS Installation
4.opencv Installation: It's actually a decompression process, with active code and compiled binaries after installation
3. Compilation:
1. Open...cmake-3.11.1-win64-x64\bin\cmake-gui.exe
Red Standard 1 Selects opencv Source Path
Red Standard 2 is the binary storage path compiled for the new opencv
2. Once selected and newly created, click on the red sign 3 and the following graphical interface appears:
Red Standard 1 chooses the compiler, and here we choose vs 14 2015 (14 is the internal version number, which is what we often call vs2015)
Red 2 is not required
Select Use default native compiler at red label 3
Click Finish when configuration is complete
3. Open and wait 1 minute for configuration to complete, the interface shows as follows:
Since we are developing opencv with QT, we need to find WITH in the red area, select WITH_QT and WITH_OPENGL below it, and uncheck WITH_IPP (otherwise an error will occur during compilation) and confifigure again.
4. The interface has the following picture error:
This is a reminder that we have some variables not found that we need to configure manually, ps: This is because we configure the qt-related things, so we need to add the qt-related paths to the variables
As shown above,
QT_QMAKE_EXECUTABLE
Qt5Concurrent_DIR
Qt5Core_DIR
Qt5Gui_DIR
Qt5Test_DIR
Qt5Widgets_DIR
Configuration required, find qt installation directory
QT_QMAKE_EXECUTABLE Fill:...\QT\5.6.3\msvc2015\bin\qmake.exe Qt5Concurrent_DIR Fill:...\QT\5.6.3\msvc2015\lib\cmake\Qt5Concurrent Qt5Core_DIR Fill:...\QT\5.6.3\msvc2015\lib\cmake\Qt5Core Qt5Gui_DIR Fill:...\QT\5.6.3\msvc2015\lib\cmake\Qt5Gui Qt5Test_DIR Fill:...\QT\5.6.3\msvc2015\lib\cmake\Qt5Test Qt5Widgets_DIR Fill:...\QT\5.6.3\msvc2015\lib\cmake\Qt5Widgets
5. My completed interface is as follows:
Click Configure again
6. Interface hints and variables not found:
Qt5OpenGL_DIR Fill in:.../QT/5.6.3/msvc2015/lib/cmake/Qt5OpenGL
Click Configure again
7, the current interface is no longer red (hip-hop), this is to hit Generate, wait for cmake to generate vs project file
8. Modify cmake
OpenCVCompilerOptions.cmake is found under (opencv source)...\opencvsrc\opencv\sourcescmake Open it and find it add_extra_compiler_option(-Werror=non-virtual-dtor) Comment it out and make it: #add_extra_compiler_option(-Werror=non-virtual-dtor)
9. Tap Open Project after the build, and vs2015 will open automatically.Wait a moment for it to be configured.
10, the interface is as follows:
Right-click on red label to generate
10. opencv is now fully compiled and the generated content is stored in the new folder created by Compile->1.cmake red label 2.
4. Testing
For me, the generated content exists in C:\zoom\project\opencv\src_3.4.1\opencv\mybuild_win64\install
- Configuration environment
Add the path C:\zoom\project\opencv\src_3.4.1\opencv\mybuild_win64\install\x86\vc14\bin to the system environment variable path.
5. Code testing:
Open Qt Creator, create a new empty console project, named any
- Add code or configuration
Add the following statements to the project file.pro file:
INCLUDEPATH+= C:\zoom\project\opencv\src_3.4.1\opencv\mybuild_win64\install\include\opencv \ C:\zoom\project\opencv\src_3.4.1\opencv\mybuild_win64\install\include\opencv2 \ C:\zoom\project\opencv\src_3.4.1\opencv\mybuild_win64\install\include LIBS+=-LC:\zoom\project\opencv\src_3.4.1\opencv\mybuild_win64\install\x86\vc14\lib -lopencv_calib3d341d \ -lopencv_core341d \ -lopencv_dnn341d \ -lopencv_features2d341d \ -lopencv_flann341d \ -lopencv_highgui341d \ -lopencv_imgcodecs341d \ -lopencv_imgproc341d \ -lopencv_ml341d \ -lopencv_objdetect341d \ -lopencv_photo341d \ -lopencv_shape341d \ -lopencv_stitching341d \ -lopencv_superres341d \ -lopencv_video341d \ -lopencv_videoio341d \ -lopencv_videostab341d
Add the following code to the cpp file (insert the picture to find it yourself):
#include "cv.h" #include "cxcore.h" #include "highgui.h" int main(int argc,char *argv[]) { //Declare IplImage pointer IplImage*pImg; //Load Images pImg=cvLoadImage("C:/Users/isee/Pictures/Camera Roll/psb.jpg",1); //create a window cvNamedWindow("Image",1); //Display Image cvShowImage("Image",pImg); //Wait for key cvWaitKey(0); //Destroy Window cvDestroyWindow("Image"); //Release Image cvReleaseImage(&pImg); return 0; }
Click Run: