Integrating OpenCV and Qt in QtCreator
Introduction
Linking OpenCV and using the Qt library in QtCreator can be a challenging task. Various tutorials and resources exist, but finding a comprehensive solution can be difficult. This article aims to provide a clear and thorough guide to accomplish this integration.
Installation and Setup
Creating OpenCV Binaries
QtCreator Project Configuration
QT += core QT -= gui TARGET = cvHello CONFIG += console CONFIG -= app_bundle TEMPLATE = app INCLUDEPATH += C:/Programs/opencv24/opencv_bin2/install/include LIBS += "C:/Programs/opencv24/opencv_bin2/bin/*.dll" SOURCES += main.cpp OTHER_FILES += \ img.JPG
#include <iostream> #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv/cv.h" using namespace std; int main() { cout << "Hello World!" << endl; cv::Mat mat; mat = cv::imread("img.JPG"); cvNamedWindow("hello"); cv::imshow("hello",mat); cvWaitKey(0); return 0; }
Alternative Library Linking
Instead of using "*.dll," you can manually list the necessary libraries in the LIBS variable:
LIBS += -LC:\Programs\opencv24\opencv_bin2\bin \ libopencv_core240d \ libopencv_highgui240d \ libopencv_imgproc240d \ libopencv_features2d240d \ libopencv_calib3d240d \
This alternative method can also resolve any issues when listing the DLLs manually.
The above is the detailed content of How to Successfully Integrate OpenCV and Qt in Qt Creator?. For more information, please follow other related articles on the PHP Chinese website!