OpenCV头文件:
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
QT中OpenCV配置文件的配置
第一种方法
添加下列代码在pro文件中:
INCLUDEPATH += /usr/local/include/opencv
LIBS += -lopencv_core \
-lopencv_imgproc \
-lopencv_highgui \
-lopencv_ml \
-lopencv_video \
-lopencv_features2d \
-lopencv_calib3d \
-lopencv_objdetect \
-lopencv_contrib \
-lopencv_legacy \
-lopencv_flann
第二种方法
在pro文件夹中加入以下配置说明:
INCLUDEPATH+=E:\opencvForQt\include
INCLUDEPATH+=E:\opencvForQt\include\opencv
INCLUDEPATH+=E:\opencvForQt\include\opencv2
LIBS += -L E:\opencvForQt\lib\libopencv_*.a
完整配置:
QT += core
QT -= gui
TARGET = testOpencv
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH+=E:\opencvForQt\include
INCLUDEPATH+=E:\opencvForQt\include\opencv
INCLUDEPATH+=E:\opencvForQt\include\opencv2
LIBS += -L E:\opencvForQt\lib\libopencv_*.a
vs中opencv2.4.9的配置
-
在弹出来的“编辑系统变量”对话框中,在“变量值”这一栏添加(注意是添加,就是在这一栏的最后使用分号隔开后添加)
“path=F:\opencv\build\x86\vc10\bin;F:\opencv\build\x64\vc10\lib;”(如果是32位系统,就可以不用后面这个)。
vc9,vc10,vc11,vc12分别表示VS2008,VS2010,VS2012,VS2013的VisualStudio使用的编译器版本,根据自己的VS版本来填写正确的编译器版本号 -
点击项目->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(反键属性)即可打开属性页,点击属性,如下图:
-
通用属性 ->VC++目录 ->包含目录中->编辑,如下图:然后添加上一下三个目录:
F:\opencv\build\include
F:\opencv\build\include\opencv
F:\opencv\build\include\opencv2 -
通用属性 ->VC++目录 ->库目录。添加上:
F:\opencv\build\x86\vc10\lib
F:\opencv\build\x64\vc10\lib
对于32位操作系统来说,这里肯定选择x86,而对于64为操作系统来说,看你自己编译的时候用哪个编译器,假如用Win32则是x86,假如是选择的是x64,则用x64,如下图:
- 链接库的配置
属性管理器”工作区中,点击项目 ->Debug|Win32->Microsoft.Cpp.Win32.userDirectories(右键属性)即可打开属 性页面。通用属性 ->链接器->输入->附加的依赖项
其中249代表的是2.4.9版本,假如是其他版本,比如2.4.8,则把249改成248。2.4.10版本改成2410。(19个带“d”的debug版本;19个不带“d”的release版本)
添加以下库:
opencv_ml249d.lib
opencv_calib3d249d.lib
opencv_contrib249d.lib
opencv_core249d.lib
opencv_features2d249d.lib
opencv_flann249d.lib
opencv_gpu249d.lib
opencv_highgui249d.lib
opencv_imgproc249d.lib
opencv_legacy249d.lib
opencv_objdetect249d.lib
opencv_ts249d.lib
opencv_video249d.lib
opencv_nonfree249d.lib
opencv_ocl249d.lib
opencv_photo249d.lib
opencv_stitching249d.lib
opencv_superres249d.lib
opencv_videostab249d.lib
opencv_objdetect249.lib
opencv_ts249.lib
opencv_video249.lib
opencv_nonfree249.lib
opencv_ocl249.lib
opencv_photo249.lib
opencv_stitching249.lib
opencv_superres249.lib
opencv_videostab249.lib
opencv_calib3d249.lib
opencv_contrib249.lib
opencv_core249.lib
opencv_features2d249.lib
opencv_flann249.lib
opencv_gpu249.lib
opencv_highgui249.lib
opencv_imgproc249.lib
opencv_legacy249.lib
opencv_ml249.lib
注:
解决方案:
1>LINK : fatal error LNK1104: 无法打开文件“cv.lib”
由于cv.lib是opencv1.0的,下载opencv1.0
链接: http://pan.baidu.com/s/1qY1ZWsc 密码: zzyb
http://www.cnblogs.com/xiaochige/p/5990858.html
相关配置:
https://www.cnblogs.com/xiaochige/p/5991187.html