Home >Backend Development >C++ >How to Successfully Link OpenCV and Qt Libraries in Qt Creator?

How to Successfully Link OpenCV and Qt Libraries in Qt Creator?

Linda Hamilton
Linda HamiltonOriginal
2024-12-01 21:13:12639browse

How to Successfully Link OpenCV and Qt Libraries in Qt Creator?

Linking OpenCV in QtCreator with Qt Library

Problem: Despite following guidance, attempts to link OpenCV and the Qt library in QtCreator have been unsuccessful.

Installation:

  1. Ensure QtCreator is installed with the Qt and MinGW toolkits.
  2. Download the OpenCV installer and extract it to a directory without spaces in the path.
  3. Install cmake and set the PATH environment variable to include MinGW's compiler path.
  4. Utilize cmake-gui to generate MinGW Makefiles and specify compiler paths.
  5. Unselect "WITH_TBB," "WITH_IPP," and "WITH_CUDA" while selecting "WITH_QT" and setting "CMAKE_BUILD_TYPE" to "Debug."
  6. Compile and install OpenCV by navigating to the opencv_bin directory and executing "mingw32-make" and "mingw32-make install."
  7. Add the QtCreator bin path to the PATH variable.

Project Configuration in QtCreator:

  1. Create a new console application.
  2. Include the following line in the .pro file:

    INCLUDEPATH += C:/Programs/opencv24/opencv_bin2/install/include
  3. Add the following lines to the .pro file:

    LIBS += -LC:\Programs\opencv24\opencv_bin2\bin \
    libopencv_core240d \
    libopencv_highgui240d \
    libopencv_imgproc240d \
    libopencv_features2d240d \
    libopencv_calib3d240d
  4. Ensure the main.cpp file includes the necessary OpenCV headers and correctly employs OpenCV functions.

The above is the detailed content of How to Successfully Link OpenCV and Qt Libraries in Qt Creator?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn