opencv的配置、使用
一、将下载后的文件解压到:E:\Opencv
二、配置opencv的环境变量:系统path添加
E:\Opencv\opencv\build\x86\vc11;
E:\Opencv\opencv\build\common\tbb\ia32\vc11;
E:\Opencv\opencv\build\x86\vc11\bin;
vc10是指VS2010,vc11是指VS2012
三、在vs2012中新建空项目,并添加cpp文件
四、配置工程的opencv依赖(每次新建工程都要重新配置,要执行此步骤请先建立工程)
1)、项目(菜单项)->…属性-> 配置属性 ->VC++目录:需要配置“包含目录”和“库目录”两项。
包含目录
E:\Opencv\opencv\build\include
E:\Opencv\opencv\build\include\opencv
E:\Opencv\opencv\build\include\opencv2(可先不选)
库目录
E:\Opencv\opencv\build\x86\vc11\lib
2)、项目(菜单项)->…属性->链接器->输入->附加依赖项
DEBUG:
opencv_calib3d248d.lib
opencv_contrib248d.lib
opencv_core248d.lib
opencv_features2d248d.lib
opencv_flann248d.lib
opencv_gpu248d.lib
opencv_highgui248d.lib
opencv_imgproc248d.lib
opencv_legacy248d.lib
opencv_ml248d.lib
opencv_objdetect248d.lib
opencv_ts248d.lib
opencv_video248d.lib
在opencv中,debug和release的附加依赖项不一样,弄混了可以编译,但是运行时会出错
c++的执行过程:编译、链接、运行,而附加依赖项应该是各种动态函数库,其在运行的过程中链接到编译出的目标文件,形成最终的可运行二进制文件
RELEASE:(可不要)
opencv_calib3d248.lib
opencv_contrib248.lib
opencv_core248.lib
opencv_features2d248.lib
opencv_flann248.lib
opencv_gpu248.lib
opencv_highgui248.lib
opencv_imgproc248.lib
opencv_legacy248.lib
opencv_ml248.lib
opencv_objdetect248.lib
opencv_ts248.lib
opencv_video248.lib
五、测试代码(把图片改名为pp.jpg,然后放到工程项目的test文件夹里面(是里面那个test文件夹)
#include <opencv2\opencv.hpp>
#include <iostream>
#include <string>
using namespace cv;
using namespace std;
int main()
{
Mat img = imread("pp.jpg");
if(img.empty())
{
cout<<"error";
return -1;
}
imshow("xx的靓照",img);
waitKey();
return 0;
}
六、错误:没有找到 opencv_core248d.dll
方法一:将D:\Program Files\OpenCV2.3.1\build\x86\vc10\bin下的所有.dll文件拷贝到system32下
方法二:将D:\Program Files\OpenCV2.3.1\build\x86\vc11\bin下的该程序需要的.dll文件拷贝到所创工程文件夹的Debug下
方法三:!!!!添加 E:\Opencv\opencv\build\x86\vc11\bin 到系统环境变量的PATH