Qt5.14_MinGW_64bit+CMake_3.24+OpenCV_4.5.1 environment construction under Windows


foreword

This article mainly describes the complete process of using Qt5.14_MinGW64 and CMake to build the OpenCV environment on the Window platform. The article describes the detailed steps of compiling OpenCV, and summarizes the related problems and solutions in the process. The relevant software can be found in Download the network disk link in the text.

1. Introduction to configuration environment

I chose opencv_4.5.1 here. My Qt version is 5.14.1. When carrying the latest opencv_4.6.0, there will always be some problems and no solution can be found. The opencv_4.5.1 version used later is relatively stable and has no problems. , so it is also recommended to use this version of opencv.

Windows环境:Win10_64bit
Qt构建环境:Qt5.14_MinGW_64bit
CMake版本:cmke_3.24.1
OPenCV版本:opencv_4.5.1

The following network disk link contains the CMake installation package and opencv source code:
My Baidu network disk link: https://pan.baidu.com/s/1utL1wKXifmCbMq5Cv6pFKQ
Extraction code: xxcj

Please add a picture description

Tip: After decompressing the compressed package in the network disk, you can see the following files under \CMake+OpenCV\opencv-4.5.1_Source.cache\ffmpeg\ (downloaded from the official website does not have these files): Solve the
Please add a picture description
problem The problem that opencv_videoio_ffmpeg.dll and opencv_videoio_ffmpeg_64.dll cannot be downloaded normally during CMake Configure of version source code, please refer to the problem solving below for details.

2. Compile OpenCV

There are many blogs with pictures and texts on CSDN to show the steps of compiling OpenCV. Here you can refer to this article: Qt configuration OpenCV tutorial, personal test has been tried (detailed version) . According to the referenced blog post, if you are using the files in the link on my online disk above, you can skip the software installation part, and then enter the step of using CMake to start compiling the OpenCV source code. Here is a summary of the compilation steps: 1. Compile
Qt Add the bin path of the browser and CMake to the system environment variable:
insert image description here

2. Open CMake, configure the source code and target path, check Advanced, and then click Configure for the first time;

3. Select MingW Makefiles, select Specify native compilers, select the corresponding compiler after Next, and click Finish; the
compiler can be confirmed through QtCreator Tools –> Options –> Kits –> Compiler:
Please add a picture description

4. After configuring done, check WITH_OPENGL and WITH_QT, and click Configure for the second time;

5. After configuring done, modify and confirm that the Value of the red entry is correct (generally no modification is required), click Configure for the third time;

6. After configuring done, it is found that the red color of the interface disappears, click Generate;

7. Enter the opencv_Build folder you created in step 2 above, hold down the shift key and click the right mouse button at the same time, click here to open the Powershell window, and enter Windows Powershell (you can see that some enter cmd, which is the same), enter Press Enter after the following command;

//mingw32-make      //不使用多线程
mingw32-make -j 8   //让CPU进行多任务处理,可以加快编译速度

Note: The number 8 here can be modified. If your computer is lower than 4-core CPU-8 threads, you need to check the number of threads in your computer and modify the number accordingly (my own computer is 4 threads and changed to - j 4, if the company computer has 12 threads, it is changed to -j 12), refer to: check the current number of threads of your own computer ;

8. After waiting for 100% completion, enter the following command and press Enter;

mingw32-make install

9. After the compilation is complete, the install folder will appear in the Build file:
insert image description here

10. Add the build bin path to the system environment variable:
Please add a picture description

3. Problem solving

1. The download of opencv_videoio_ffmpeg.dll and opencv_videoio_ffmpeg_64.dll timed out
. If you use the opencv source code downloaded from the official website for Cmake, this problem will occur if you cannot access the external network during the Configure process. Ignoring this problem can also make CMake successful, but later in Qt It is impossible to play video with OpenCV (I had the problem of not being able to play the video, and later I found out that it was the bomb that was planted at this time, and it took a lot of time to solve it), here I suggest directly using the link in my network disk The source code is compiled, and the relevant files have been downloaded and name processed. Of course, there are problems like dll download timeout. For specific solutions, please refer to this blog: Solution to download failure of opencv_ffmpeg.dll when compiling OpenCV3.4.6 with CMake

Summarize

This article is done here, and you can use OpenCV in Qt later. The specific usage method will not be introduced here. You can check the reference blog at the end of the article. The configuration of this environment is not easy for beginners. It is more troublesome to search for problems after missing some content, so we need to be more careful in the process. This article is also a summary and sharing of my study, I hope it can be helpful to everyone.


hello:
Learn together and make progress together. If you still have related questions, you can leave a message in the comment area for discussion.

Reference blog:
Qt configuration OpenCV tutorial, personal test has been tried (detailed version)
Check the number of threads on your own computer
CMake compiles OpenCV3.4.6 Opencv_ffmpeg.dll and other download failure solutions
Qt5.11.2+CMake+opencv configuration and problem summary Play video on Qt control using OpenCV in
QT (simple test routine)

Guess you like

Origin blog.csdn.net/XCJandLL/article/details/126596792
Recommended