我是Qt的新手,我有一个需要在Qt中配置OpenCV的项目,我试图在Qt中运行一个简单的代码,但是我得到了这个错误"对cv::imread(std::string const&, int)
的未定义引用"
这是我的代码...
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
using namespace cv;
int main(){
Mat src,gray;
src=imread("C:/Users/user/Desktop/wood-pattern.png",1);
imshow("gg",src);
cvWaitKey(0);
return 0;
}
我的source.pro是
#-------------------------------------------------
#
# Project created by QtCreator 2014-08-24T20:38:56
#
#-------------------------------------------------
INCLUDEPATH += C:\opencv\opencv2.4.9\build\include\
CONFIG(release,debug|release)
{
LIBS += C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_calib3d249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_contrib249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_core249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_features2d249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_flann249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_gpu249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_highgui249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_imgproc249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_legacy249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_ml249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_objdetect249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_ts249.lib \
C:\opencv\opencv2.4.9\build\x86\vc11\lib\opencv_video249.lib
}
CONFIG(debug,debug|release)
{
LIBS += C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_calib3d249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_contrib249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_core249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_features2d249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_flann249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_gpu249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_highgui249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_imgproc249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_legacy249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_ml249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_objdetect249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_ts249.lib \
C:\opencv\opencv2.4.9\build\x64\vc11\lib\opencv_video249.lib \
}
QT += core
QT -= gui
TARGET = Source
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
我看到了所有答案,但他们没有工作。 我的Qt是32位,我的Windows是64位。 我认为我的配置错了。我遵循了许多教程,但他们不适合OpenCV 2.4.9所以请帮助我......
答案 0 :(得分:2)
请参阅pkg-config opencv --libs
的输出,找出您缺少的库,然后将它们添加到您的配置中。
对我来说,完整的库列表是
/usr/lib64/libopencv_calib3d.so.2.4.8
/usr/lib64/libopencv_contrib.so.2.4.8
/usr/lib64/libopencv_core.so.2.4.8
/usr/lib64/libopencv_features2d.so.2.4.8
/usr/lib64/libopencv_flann.so.2.4.8
/usr/lib64/libopencv_gpu.so.2.4.8
/usr/lib64/libopencv_highgui.so.2.4.8
/usr/lib64/libopencv_imgproc.so.2.4.8
/usr/lib64/libopencv_legacy.so.2.4.8
/usr/lib64/libopencv_ml.so.2.4.8
/usr/lib64/libopencv_nonfree.so.2.4.8 # you don't have this one
/usr/lib64/libopencv_objdetect.so.2.4.8
/usr/lib64/libopencv_photo.so.2.4.8 # this one
/usr/lib64/libopencv_stitching.so.2.4.8 # this one
/usr/lib64/libopencv_superres.so.2.4.8 # and this one
/usr/lib64/libopencv_ts.a
/usr/lib64/libopencv_video.so.2.4.8
答案 1 :(得分:0)
不了解Windows,但如果它有pkg-config
,您应该可以通过添加
PKGCONFIG += opencv
到您的项目文件中(假设您的OpenCV安装正确的package-config文件,就像在理智的平台上一样)。
答案 2 :(得分:0)
在我的情况下,它只是参数的顺序,请注意
g++ main.cpp -o main `pkg-config --libs --cflags opencv`
工作时
g++ -o main `pkg-config --libs --cflags opencv` main.cpp
并不是因为后者在 main.cpp
被引用之前定义了main.cpp
需要的内容。