I tried two methods to use opencv with qt creator first one using Mingw where the dlls and .dll.a files are already downloaded with the opencv library and I just add reference to the .dll.a files in the .pro file as follow
INCLUDEPATH += D:\\OpenCV\\opencv\\build\\include
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_calib3d242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_contrib242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_core242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_features2d242.dll.a
I have a simple code to test opencv:
#include <QtCore/QCoreApplication>
#include <opencv/cv.h>
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat image;
return a.exec();
}
but I got a build issues as follow
C:\Users\Kato\Documents\QT projects\QtOpenCVYaRab\debug\main.o:-1: In function
~Mat': d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:278: error: undefined reference to
cv::fastFree(void*)' d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:367: error: undefined reference to `cv::Mat::deallocate()' :-1: error: collect2: ld returned 1 exit status
Here is some of the compile output:
Running build steps for project QtOpenCVYaRab...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Users/Kato/Documents/QT projects/QtOpenCVYaRab'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
debug/main.o:d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QtOpenCVYaRab.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project QtOpenCVYaRab (target: Desktop)
When executing build step 'Make'
the second method is using cmake to compile the opencv library the using visual studio 2010 to build it and add references to the files in the bin folder but I got almost the same building issues.
this is ur main.cpp...the above programme displays the picture of lena...use double backslashes for indicating change of directory on windows platform...some how the imread does work for me so i have loaded the image as IplImage and casted it to Mat...u cn do the following also..
your .pro file should have the following lines as mentioned earlier...
and your system variable named path should have
after editing the path variable close the Qt ide/application and restart it for the system variable change to get reflected..
You have to specify your library path with -L and then add the library file with
For unix (installed in default place):
For windows (your problem):
From the error mentioned, it seems that Opencv library is missing some files/components.Please start with the simple program for Opencv. This program just display the camera image.
Please follow the given link.
http://linux.softpedia.com/get/Multimedia/Graphics/qwebcam-38246.shtml
Download the source code for qwebcam and follow the instruction to setup Opencv. This is a very simple source code and works fine (tested on Linux-os).
I recently tried with Opencv & this link was quiet useful for me to begin with.
Hope you will be able to resolve your error through this code.
if u are running it as an console application then no need to include QtCore/QtApplication
I ran into the same problem, but altering the .pro manually didn't work for me. Eventually I found a simple solution to connect the openCV to Qt. I posted about it a few other threads, https://stackoverflow.com/a/51914928/10245006 and have included the information below.
The steps listed below are found in the Qt5 documentation: [http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html][1] under the "To Add Library" section.
Let me add some specificity from here...