您的位置:首页 > 编程语言 > Qt开发

Qt+Opencv配置

2016-12-02 14:24 134 查看
在Win7(32)位下:1、版本:    Qt版本:qt-opensource-windows-x86-android-5.5.1.exe    链接地址:http://download.qt.io/archive/qt/5.5/5.5.1/    OpenCV版本:OpenCV2.4.12、安装好Qt之后,将D:\Program Files\opencv\build\x86\vc10\bin,D:\qt\5.5\mingw492_32\bin的路径添加到Path中,在创建工程的时候,向工程    .pro文件中添加: INCLUDEPATH+="D:/ProgramFiles/opencv/build/include"\
"D:/Program Files/opencv/build/include/opencv" \
"D:/Program Files/opencv/build/include/opencv2"
LIBS+= -L"D:/Program Files/opencv/build/x86/vc10/lib/" -lopencv_ml2411d -lopencv_calib3d2411d -lopencv_contrib2411d -lopencv_core2411d \
-lopencv_features2d2411d -lopencv_flann2411d -lopencv_gpu2411d -lopencv_imgproc2411d -lopencv_legacy2411d -lopencv_objdetect2411d \
-lopencv_ts2411d -lopencv_video2411d -lopencv_nonfree2411d -lopencv_ocl2411d -lopencv_photo2411d -lopencv_stitching2411d \
-lopencv_superres2411d -lopencv_videostab2411d -lopencv_highgui2411d
  表达式的第一部分(
-L...
):使链接器知道应该在哪个目录中查找库文件。双引号只在路径包含空格时才需要。  表达式的第二部分(
-l...
):告诉链接器链接哪些库,没有必要指定 .lib 扩展名。3、main.cpp如下:
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main()
{
IplImage *src = cvLoadImage("Example1.png", -1);
cvShowImage("src", src);
cvWaitKey(0);
cvReleaseImage(&src);
return 0;
}
并把Example1.png图片拷贝到Debug目录下,可以正常打开图片,但是将main.cpp函数改成以下:
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main()
{
/* IplImage *src = cvLoadImage("Example1.png", -1);
cvShowImage("src", src);
cvWaitKey(0);
cvReleaseImage(&src);*/
Mat src = imread("Example1.png", 0);
imshow("src", src);
waitKey(0);
 return 0;
}
编译出现错误:
   debug/main.o: In function `main':   C:\Users\Administrator.AZU9F7UB7BS30XB\Desktop\test\build-55y-Desktop_Qt_5_5_1_MinGW_32bit-Debug/../55y/main.cpp:11: undefined reference to `cv::imread(std::string const&, int)'   C:\Users\Administrator.AZU9F7UB7BS30XB\Desktop\test\build-55y-Desktop_Qt_5_5_1_MinGW_32bit-Debug/../55y/main.cpp:12: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'   C:\Users\Administrator.AZU9F7UB7BS30XB\Desktop\test\build-55y-Desktop_Qt_5_5_1_MinGW_32bit-Debug/../55y/main.cpp:12: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'   C:\Users\Administrator.AZU9F7UB7BS30XB\Desktop\test\build-55y-Desktop_Qt_5_5_1_MinGW_32bit-Debug/../55y/main.cpp:13: undefined reference to `cv::waitKey(int)'   debug/main.o: In function `ZN2cv3MatD1Ev':   D:/Program Files/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'   debug/main.o: In function `ZN2cv3Mat7releaseEv':   D:/Program Files/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'   collect2.exe: error: ld returned 1 exit status   Makefile.Debug:77: recipe for target 'debug\55y.exe' failed   mingw32-make[1]: *** [debug\55y.exe] Error 1   mingw32-make[1]: Leaving directory 'C:/Users/Administrator.AZU9F7UB7BS30XB/Desktop/test/build-55y-Desktop_Qt_5_5_1_MinGW_32bit-Debug'   makefile:34: recipe for target 'debug' failed   mingw32-make: *** [debug] Error 2  14:42:15: 进程"D:\qt\Tools\mingw492_32\bin\mingw32-make.exe"退出,退出代码 2 。   Error while building/deploying project 55y (kit: Desktop Qt 5.5.1 MinGW 32bit)   When executing step "Make"  说明编译器找不到lib库文件,opencv2中新添加函数和结构不能用,例如:Mat结构,imread函数,VideoCapture结构等;

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  opencv qt