Author:Maddock windows
Date:2014.12.27ide
……………………………………………………………………………………………………函數
PS: VS2013 + OPENCV 3.0.0 的安裝,鏈接器的輸入選項簡化爲:工具
#ifndef _OPENCV_LIB_
#define _OPENCV_LIB_
#ifdef _DEBUG
#pragma comment(lib, "opencv_ts300d.lib")
#pragma comment(lib, "opencv_world300d.lib")
#else
#pragma comment(lib, "opencv_ts300.lib")
#pragma comment(lib, "opencv_world300.lib")
#endif
#endif測試
其餘步驟相同。ui
不過,目前opencv3.0.0的using namespace cv和windows.h中ACCESS_MASK定義衝突,spa
錯誤 4 error C2872: 「ACCESS_MASK」: 不明確的符號 c:\program files (x86)\windows kits\8.1\include\um\winnt.h 9084 1 opencvtest
.net
註釋掉using namespace cv
,再全部須要用到cv的地方加cv::……………………………………………………………………………………………debug
準備工具 windows平臺 opencv2.4.10 vs20133d
1解壓opencv2.4.10.exe,我放在目錄 C:\Adisk\software\opencv\opencv2410\opencv
配置環境變量
Path: C:\Adisk\software\opencv\opencv2410\opencv\build\x86\vc12\bin
在x86文件夾內還有vc10,vc11,vc12 3個文件夾,分別對應vs2010,vs2012,vs2013
2 配置VS2013的include 和lib目錄
新建win32工程,打開屬性管理器(視圖–>其餘窗口–>屬性管理器)
右鍵Debu32中的Mirosoft.Cpp.Win32.user選擇屬性,能夠看見
編輯包含目錄和庫目錄
包含目錄 C:\Adisk\software\opencv\opencv2410\opencv\build\include
庫目錄 C:\Adisk\software\opencv\opencv2410\opencv\build\x86\vc12\lib
下一步點擊鏈接器的輸入選項,編輯附加依賴項,加入
opencv的debug版本和release版本須要的lib不一樣,可是在編輯右鍵Debu32中的Mirosoft.Cpp.Win32.user選擇屬性這一步中,相應的
release版本也跟着變了,若是編譯運行debug版本是沒有問題,切換到release版本是須要把debug版本去掉,不然opencv中的部分函數將不能
運行。
debug版本
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_core2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_legacy2410d.lib
opencv_ml2410d.lib
opencv_nonfree2410d.lib
opencv_objdetect2410d.lib
opencv_ocl2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
opencv_videostab2410d.lib
release版本
opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_core2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_legacy2410.lib
opencv_ml2410.lib
opencv_nonfree2410.lib
opencv_objdetect2410.lib
opencv_ocl2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_videostab2410.lib
3 測試
// opencvtest.cpp : 定義控制檯應用程序的入口點。
//
#include "stdafx.h"
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Mat src = imread("image.png", 0);
if (src.empty())
{
cout << "打開圖像失敗!" << endl;
return -1;
}
namedWindow("image", CV_WINDOW_AUTOSIZE);
imshow("image", src);
waitKey(0);
return 0;
}
若是出現dll文件丟失,能夠註銷帳戶或者重啓電腦是環境變量生效。
PS: 按照上述方法作的時候,在debug和release界面的附加依賴項裏其中一個編輯完,另外一個爲何也出現了和其同樣的附加依賴項?怎麼實現debug和release中的附加依賴項不同?? 哪位大俠知道解決方法,求告知!!!!!
參考方案:
每次編寫代碼在前面加入下面的代碼,能夠不用配置編輯附加依賴項
參考來源:http://blog.csdn.net/xiaohuh421/article/details/7476485
#ifdef _DEBUG
#pragma comment(lib,"..\\debug\\LedCtrlBoard.lib")
#else
#pragma comment(lib,"..\\release\\LedCtrlBoard.lib")
#endif
#ifdef _DEBUG
#pragma comment(lib, "opencv_calib3d2410d.lib")
#pragma comment(lib, "opencv_contrib2410d.lib")
#pragma comment(lib, "opencv_core2410d.lib")
#pragma comment(lib, "opencv_features2d2410d.lib")
#pragma comment(lib, "opencv_flann2410d.lib")
#pragma comment(lib, "opencv_gpu2410d.lib")
#pragma comment(lib, "opencv_highgui2410d.lib")
#pragma comment(lib, "opencv_imgproc2410d.lib")
#pragma comment(lib, "opencv_legacy2410d.lib")
#pragma comment(lib, "opencv_ml2410d.lib")
#pragma comment(lib, "opencv_nonfree2410d.lib")
#pragma comment(lib, "opencv_objdetect2410d.lib")
#pragma comment(lib, "opencv_photo2410d.lib")
#pragma comment(lib, "opencv_stitching2410d.lib")
#pragma comment(lib, "opencv_ts2410d.lib")
#pragma comment(lib, "opencv_video2410d.lib")
#pragma comment(lib, "opencv_videostab2410d.lib")
#else
#pragma comment(lib, "opencv_calib3d2410.lib")
#pragma comment(lib, "opencv_contrib2410.lib")
#pragma comment(lib, "opencv_core2410.lib")
#pragma comment(lib, "opencv_features2d2410.lib")
#pragma comment(lib, "opencv_flann2410.lib")
#pragma comment(lib, "opencv_gpu2410.lib")
#pragma comment(lib, "opencv_highgui2410.lib")
#pragma comment(lib, "opencv_imgproc2410.lib")
#pragma comment(lib, "opencv_legacy2410.lib")
#pragma comment(lib, "opencv_ml2410.lib")
#pragma comment(lib, "opencv_nonfree2410.lib")
#pragma comment(lib, "opencv_objdetect2410.lib")
#pragma comment(lib, "opencv_photo2410.lib")
#pragma comment(lib, "opencv_stitching2410.lib")
#pragma comment(lib, "opencv_ts2410.lib")
#pragma comment(lib, "opencv_video2410.lib")
#pragma comment(lib, "opencv_videostab2410.lib")
#endif
若是以爲每次添加比較麻煩,能夠採用以下一勞永逸的方案:
新建一個opencv_lib.h文件,編輯內容:
#ifndef _OPENCV_LIB_
#define _OPENCV_LIB_
#ifdef _DEBUG
#pragma comment(lib, "opencv_calib3d2410d.lib")
#pragma comment(lib, "opencv_contrib2410d.lib")
#pragma comment(lib, "opencv_core2410d.lib")
#pragma comment(lib, "opencv_features2d2410d.lib")
#pragma comment(lib, "opencv_flann2410d.lib")
#pragma comment(lib, "opencv_gpu2410d.lib")
#pragma comment(lib, "opencv_highgui2410d.lib")
#pragma comment(lib, "opencv_imgproc2410d.lib")
#pragma comment(lib, "opencv_legacy2410d.lib")
#pragma comment(lib, "opencv_ml2410d.lib")
#pragma comment(lib, "opencv_nonfree2410d.lib")
#pragma comment(lib, "opencv_objdetect2410d.lib")
#pragma comment(lib, "opencv_photo2410d.lib")
#pragma comment(lib, "opencv_stitching2410d.lib")
#pragma comment(lib, "opencv_ts2410d.lib")
#pragma comment(lib, "opencv_video2410d.lib")
#pragma comment(lib, "opencv_videostab2410d.lib")
#else
#pragma comment(lib, "opencv_calib3d2410.lib")
#pragma comment(lib, "opencv_contrib2410.lib")
#pragma comment(lib, "opencv_core2410.lib")
#pragma comment(lib, "opencv_features2d2410.lib")
#pragma comment(lib, "opencv_flann2410.lib")
#pragma comment(lib, "opencv_gpu2410.lib")
#pragma comment(lib, "opencv_highgui2410.lib")
#pragma comment(lib, "opencv_imgproc2410.lib")
#pragma comment(lib, "opencv_legacy2410.lib")
#pragma comment(lib, "opencv_ml2410.lib")
#pragma comment(lib, "opencv_nonfree2410.lib")
#pragma comment(lib, "opencv_objdetect2410.lib")
#pragma comment(lib, "opencv_photo2410.lib")
#pragma comment(lib, "opencv_stitching2410.lib")
#pragma comment(lib, "opencv_ts2410.lib")
#pragma comment(lib, "opencv_video2410.lib")
#pragma comment(lib, "opencv_videostab2410.lib")
#endif
#endif
將該文件放入opencv的安裝目錄:C:\Adisk\software\opencv\opencv2410\opencv\build\include\opencv2\opencv_lib.h也就是和 #include <opencv2/opencv.hpp>在同一個目錄,以後只須要包含頭文件 #include <opencv2/opencv_lib.h>
就能夠在Debug和Release版本之間任意切換