QT5.6+OpenCV3.4.1+CMake compilation

1. Install QT5.6, remember to check mingw when installing.

2. Install CMake3.11.1

CMake download address: https://cmake.org/download/

Select source file and destination directory




Click configure, select



Choose a compiler:



During the configuration process, it may be stuck at: FFMPEG: Download: opencv_ffmpeg.dll, click stop first, and then click configure.

If not, wait a little longer.

After waiting for the configuration to complete, check opengl and QT



Then click configure, then an error will be reported. We modify the path and lib library of qmake, as shown in the figure:


Click configure again, report an error, modify the opengl path,:



The last step, click directly: Generate: Generating done appears, indicating that the creation of the Makefile is completed


Next, cmd switches to the target directory, for example I am: C:\Users\11011430\Desktop\opencv\BD

Enter the command: mingw32-make to compile.



Problems during compilation:

1.tubs\io_win32.cc:94:3: warning: identifier 'nullptr' is a keyword in C++11

Solution: Check C++11 support and re-Generating


2.

About 28% encounter this kind of error:
... windres.exe: unknown option -- W ...

Solution:
uncheck ENABLE_PRECOMPILED_HEADERS in cmake

3.
About 32% encounter this kind of error:
'sprintf_instead_use_StringCbPrintfA_or_StringCchPrintfA' was not declared in this scope ...
solution:
在..\opencv\sources\modules\videoio\src\cap_dshow.cpp
Add #define NO_DSHOW_STRSAFE before the line #include "DShow.h"


After mingw32-make completes, use mingw32-make install to install

Create a new folder qt-opencv, copy the include folder under C:\Users\11011430\Desktop\opencv\build and the lib and bin folders under the installation target file to qt-opencv



Then create a new QT empty project, add main.cpp, and modify the .pro file:

SOURCES += \
    main.cpp
INCLUDEPATH+=C:\Users\11011430\Desktop\opencv-qt\include\opencv\
            C:\Users\11011430\Desktop\opencv-qt\include\opencv2\
            C:\Users\11011430\Desktop\opencv-qt\include

LIBS+=C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_calib3d_pch_dephelp.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_calib3d341.dll.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_core_pch_dephelp.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_core341.dll.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_dnn_pch_dephelp.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_dnn341.dll.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_features2d_pch_dephelp.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_features2d341.dll.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_flann_pch_dephelp.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_flann341.dll.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_highgui_pch_dephelp.a\
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_highgui341.dll.a \
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgcodecs_pch_dephelp.a \
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgcodecs341.dll.a \
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgproc_pch_dephelp.a \
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_imgproc341.dll.a \
      C:\Users\11011430\Desktop\opencv-qt\lib\libopencv_ml_pch_dephelp.a

The main.cpp file is:

#include"cv.h"
#include"cxcore.h"
#include"highgui.h"



int main(int argc,char* argv[])

{

    //declare the IplImage pointer
    IplImage*pImg;
    //load image
    pImg=cvLoadImage("F:1.jpg",1);
    //create window
    cvNamedWindow("Image",1);
    //display image
    cvShowImage("Image",pImg);
    //wait for button
    cvWaitKey(0);
    //destroy the window
    cvDestroyWindow("Image");
    // release the image
    cvReleaseImage(&pImg);
    return 0;
}

Running, the test is successful, only some library files are added in the test, and they are added in the actual development. Attach the gadget to add all the libraries:

https://download.csdn.net/download/qq_31208451/10398028

Test chart, haha. . . .



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325946985&siteId=291194637