Home >Backend Development >C++ >How to Integrate OpenCV with Qt Creator for Image Processing?
How to Link OpenCV in QtCreator and Use Qt Library
This guide provides detailed instructions on how to integrate OpenCV with QtCreator and utilize the functionality of both libraries in your projects.
Installation and Setup:
Configure OpenCV using CMake-GUI:
Creating a QtCreator Project:
In the project file (.pro), add the following:
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
In main.cpp, include the necessary headers and implement OpenCV image processing:
#include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "opencv/cv.h" using namespace std; int main() { cv::Mat mat; mat = cv::imread("img.JPG"); cvNamedWindow("hello"); cv::imshow("hello",mat); cvWaitKey(0); return 0; }
Linking Libs:
The key to integrating OpenCV with QtCreator is correctly linking the required libraries. In the .pro file, specify the following:
LIBS += -LC:\Programs\opencv24\opencv_bin2\bin \ libopencv_core240d \ libopencv_highgui240d \ libopencv_imgproc240d \ libopencv_features2d240d \ libopencv_calib3d240d
These commands instruct QtCreator to link the specified OpenCV libraries (.dll files) with your project.
By following these steps, you can successfully link OpenCV with QtCreator and utilize both libraries' capabilities in your application.
The above is the detailed content of How to Integrate OpenCV with Qt Creator for Image Processing?. For more information, please follow other related articles on the PHP Chinese website!