Configure and use QT creator + openCV in windows, creatoropencv
The online tutorials teach you how to use minGW and cmake to compile opencv and then import it. This is too troublesome and is not conducive to new users. Here is a simple method.
1.Install qt sdk
I installed 32-bit qt 5.3 msvc with built-in qt creator and directly used the msvc compiler in windows.
2.Install opencv
I installed opencv2.4.9 for windows and decompressed it to the root directory of drive D.
Note that opencv for windows has a build folder after decompression, which indicates that it is compiled using the msvc compiler. If we use the msvc compiler, we can directly import the Link Library and header files, you don't need to compile minGW and cmake on the Internet. If qt is installed in minGW, you need to re-compile opencv with cmake.
3.Create a standard console C ++ project in qt creator.
Any project can be created. The simplest C ++ console project can be directly created here.
4.Configure the environment variables of opencv (this step seems saving, but it is always safe to configure an environment variable)
Http://blog.csdn.net/u012234115/article/details/38612977 in another blog
5.Modify the project's pro file.
To include the header file directory and the static Connection Library directory, add
INCLUDEPATH+=d:/opencv/build/include/opencv \ d:/opencv/build/include/opencv2 \ d:/opencv/build/includeLIBS+=D:\opencv\build\x86\vc12\lib\opencv_ml249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_calib3d249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_contrib249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_core249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_features2d249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_flann249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_gpu249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_highgui249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_imgproc249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_legacy249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_objdetect249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_ts249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_video249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_nonfree249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_ocl249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_photo249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_stitching249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_superres249d.libLIBS+=D:\opencv\build\x86\vc12\lib\opencv_videostab249d.lib
The above is added to the debug version library. If you want to release the version, remove the following d. The slash "/" and "\" can both represent paths, but different paths must be separated by line breaks. You can add multiple or one slash at a time for each slash, such as "\", "INCLUDEPATH", and "LIBS". Note the format.
After adding qmake, note that qmake is required.
6.Code
Main. cpp
# Include <iostream> # include <opencv2/core. hpp> # include <opencv2/highgui. hpp> using namespace std; using namespace cv; int main (int argc, char ** argv) {// IplImage * pImg = cvLoadImage ("D: /codetest/qttest/main/HelloWorld.png "); // cvShowImage (" test ", pImg); cout <" opencv "<endl; Mat src = imread (" D: /codetest/qttest/main/laura.jpg "); // reading the image in qt seems to only support the absolute path imshow (" test ", src); waitKey (0 ); return 0 ;}
The old version and the new version of the opencv API can be used. Note that reading images in qt does not seem to use relative paths. If it is a gui program, you may be able to use relative paths in the resource file, not tested.
7.Effect
Tomb liying Laura dajie domineering town building ~