VS2010 OpenCV配置
其实很简单,不过有个小问题需要注意一下,折腾了很长时间。
下载后解压到某个目录下(XX),在visual studio的新建工程里,右键属性,加三个东西即可
c++,general, Additional include directory, XX\opencv\build\include\opencv;XX\opencv\build\include\opencv2;D:\Library\opencv\build\include
link,general, Additional Library directory, XX\opencv\build\include\opencv;XX\opencv\build\include\opencv2;D:\Library\opencv\build\include
input, Addtional Dependencies ,
opencv_calib3d231d.lib
opencv_contrib231d.lib
opencv_core231d.lib
opencv_features2d231d.lib
opencv_flann231d.lib
opencv_gpu231d.lib
opencv_haartraining_engined.lib
opencv_highgui231d.lib
opencv_imgproc231d.lib
opencv_legacy231d.lib
opencv_ml231d.lib
opencv_objdetect231d.lib
opencv_ts231d.lib
opencv_video231d.lib
然后把 XX\opencv\build\x86\vc10\bin 加到环境变量里边就OK了
注意如果是Debug模式下,lib里边只能加上边这些带d的lib(debug),Release下,相应改成对应的lib(没有d),
如果在Debug模式下,把lib目录下所有的lib文件都加来,就会有问题,比如,
#include <opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main() { Mat img; img = imread("E:\\204\\testface12.jpg",CV_LOAD_IMAGE_COLOR); if(! img.data){ cout<<"Could not find image.."<<endl; return 0; } namedWindow("Display window",CV_WINDOW_AUTOSIZE); imshow("Display window",img); waitKey(0); return 0; }
虽然E:\204\testface12.jpg 文件确实存在,不过运行后,一直是Could not find image, 不过下面C风格的读入显示就没有问题
#include <opencv.hpp> #include <iostream> using namespace cv; using namespace std; int main() { IplImage* img=cvLoadImage("E:\\204\\testface12.jpg"); cvNamedWindow("name"); cvShowImage("name",img); cvWaitKey(0); return 0; }
当然,debug模式下,不把哪些没有d的lib加进来,两段代码就都没有问题了。
补充:按理说,这样应该就可以了,不过OpenCV2.3好像有点问题,比如,下面这段代码就会报错
1 #include <opencv.hpp> 2 #include <iostream> 3 4 using namespace cv; 5 using namespace std; 6 7 8 int main() 9 { 10 11 Mat img; 12 img = imread("E:\\204\\testface12.jpg",CV_LOAD_IMAGE_COLOR); 13 if(! img.data){ 14 cout<<"Could not find image.."<<endl; 15 return 0; 16 } 17 18 Mat grayimg; 19 cvtColor(img,grayimg,CV_RGB2GRAY); 20 21 imshow("gray image",grayimg); 22 waitKey(0); 23 return 0; 24 }
执行时,会报tbb_debug.dll missing, 去http://threadingbuildingblocks.org/ver.php?fid=182, 下载相应的压缩包,然后解压,取出tbb40_20120201oss\bin\ia32\vc10\tbb_debug.dll,搁到exe的路径下就可以了。
(之前用的是 tbb40_20120201oss\bin\intel64\vc10\tbb_debug, 一直有问题。。。看来只能用32bit的dll才行)
参考:
http://www.learntricks.in/2012/03/application-was-unable-to-start.html