- Prepare the required software
Mingw-gcc440_1
Qt-creator-win-opensource-2.5.0.exe
Qt-win-opensource-4.8.4-mingw.exe
Cmake-2.8.12.1-win32-x86.exe
Opencv-2.3.1-win-superpack.exe
- Software Installation
2.1 Install QT and configure the relevant environment variables.
2.2 Install CMake, the installation path is not allowed to have Chinese and white space.
2.3 Unzip OPENCV to C drive directory
- Compiling OPENCV
3.1 Open the CMake, specify the source location (that is, the OpenCV extracted from the place) and the place to store the generated files
As shown in the following:
Click the Configure button to pop up the dialog box and select Mingwmakefiles and specify native compilers
As shown in the following:
Click the Next button and the results are as follows:
Jump out of the dialog box to specify C + + and C compiler path, C with Gcc.exe, in the QT directory under the Mingw/bin subdirectory, C + + with G++.exe
Click Finish button to end back to the main screen, click the Configure button again, no error after selecting WITH_QT
As shown in the following:
Set the Cuda_toolkit_root_dir path to C:\Qt\mingw\bin
Click the Configure button again, then click Generate without error.
3.2 Compiling
A. cmd command go to generate directory (mine is as shown in D:\opencvMinGw)
CD D:\opencvMinGw
B. cmd command to compile the file
Mingw32-make
C. cmd command compile Install
Mingw32-make Install
As shown in the following:
3.3
After compiling and installing, there is an install directory under the directory where the generate generated, and all the results are compiled here, including Bin,lib and include, put the bin directory in the environment variable path, In fact, the entire install directory can be copied to a place to use, so that the contents of the OpenCV directory is completely deleted, the province occupies space. I've moved all the contents of the install into the OPENCVFORQT directory under the C drive.
- Sample test
Open the Qtcreator software to create a new console program, add an include in the project's. Pro file
And Lib as shown:
The main function code is as follows:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main ()
{
Cv::mat image = Cv::imread ("c:\\test.jpg");
Cv::namedwindow ("My Image");
Cv::imshow ("My image", image);
Cv::waitkey (5000);
return 1;
}
Run results
OPENCV Library under Windows QT compilation and use