OpenCV+Visual Studio 2010、2012、2013、2015

来源:互联网 发布:传真服务器软件 编辑:程序博客网 时间:2024/06/15 16:07

1.download opencv 2.4.10,Unzip the package into a sub-directory

这里写图片描述

2.Modify director name

A. Modify directory build/x86  name vc10、vc11、vc12 as vc100、vc110、vc120,

这里写图片描述

B.Modify directory build/x64 name vc10、vc11、vc12 as vc100、vc110、vc120,

这里写图片描述

C. modify directory  the x86 in build as win32


这里写图片描述

3.open your visual studio new a project

A


B


C


D




E


F


G



Then you can see the property manager :

A



Here may have a problem: only have debug|win32 and release|win32, have no x64,we need add debug|x64 and release|x64.

A


add debug|x64 and release|x64.








the result:  we have debug|x64 and release|x64 now!



4. Add paths of header file and  paths of library file :

A.  Debug|Win32         Microsoft.Cpp.Win32.user


edit the include directories:


edit the library directories:H:\opencv2.4.10\build/$(Platform)/vc$(PlatformToolsetVersion)/staticlib



B.do the same thing to 2、3、4 as  step A,add the same paths of header file and  same paths of library file



5.add macro definition:_CRT_SECURE_NO_WARNINGS 

A


B . also same to 2、3、4



6. write program
Write in code:

#include "stdafx.h"#include <cv.h>#include <opencv2/core/core.hpp>#include <highgui.h>using namespace cv;int _tmain(int argc, _TCHAR* argv[]){    Mat img(300, 300, CV_8UC3);    img.setTo(Scalar(0, 255));    imshow("Hello OpenCV", img);    waitKey();    return 0;}

a.open cv.h 


b.add #include <opencv/cv_import_static_lib.h>  in cv.h 


c.open core.hpp 



d.add   #include <opencv/cv_import_static_lib.h>  in core.hpp




e. core.hpp  right click ,open core.hpp containing floder 。Go to directory:H:\opencv2.4.10\build\include\opencv 





f  new txt file  add the following content and save


#pragma once#ifdef WIN32#include <opencv2/core/version.hpp>//定义宏,保证在debug模式下,导入opencv_xxxd.lib,release模式下导入opencv_xxx.lib#ifdef _DEBUG#   define CC_CVLIB(name) "opencv_" name CC_CVVERSION_ID "d.lib"#   define CC_CVLIB_2(name) "opencv_" name CC_CVVERSION_ID2 "d.lib"#   define CC_LIB(name) name "d.lib"#else#   define CC_CVLIB(name) "opencv_" name CC_CVVERSION_ID ".lib"#   define CC_CVLIB_2(name) "opencv_" name CC_CVVERSION_ID2 ".lib"#   define CC_LIB(name)   name ".lib"#endif//对于静态库,必须导入如下这些库#pragma comment(lib, "kernel32.lib")#pragma comment(lib, "user32.lib")#pragma comment(lib, "gdi32.lib")#pragma comment(lib, "Vfw32.lib")#pragma comment(lib, "winspool.lib")#pragma comment(lib, "comdlg32.lib")#pragma comment(lib, "advapi32.lib")#pragma comment(lib, "shell32.lib")#pragma comment(lib, "ole32.lib")#pragma comment(lib, "oleaut32.lib")#pragma comment(lib, "uuid.lib")#pragma comment(lib, "odbc32.lib")#pragma comment(lib, "odbccp32.lib")#pragma comment(lib, "Comctl32.lib")//如果为3版,导入方式不同#if CV_MAJOR_VERSION==3//定义cv的库名称,2410版的,如果是其他版本,则修改为指定的就好了#define CC_CVVERSION_ID       "2410"#define CC_CVVERSION_ID2       "300"//导入静态库依赖#pragma comment(lib, CC_LIB("IlmImf"))#pragma comment(lib, CC_LIB("libjasper"))#pragma comment(lib, CC_LIB("libjpeg"))#pragma comment(lib, CC_LIB("libpng"))#pragma comment(lib, CC_LIB("libtiff"))#pragma comment(lib, CC_LIB("libwebp"))#pragma comment(lib, "ippicvmt.lib")#pragma comment( lib, CC_CVLIB("calib3d") )#pragma comment( lib, CC_CVLIB_2("calib3d") )#pragma comment( lib, CC_CVLIB("contrib") )//#pragma comment( lib, CC_CVLIB("core") )#pragma comment( lib, CC_CVLIB_2("core") )//#pragma comment( lib, CC_CVLIB("core") )#pragma comment( lib, CC_CVLIB_2("features2d") )#pragma comment( lib, CC_CVLIB("features2d") )#pragma comment( lib, CC_CVLIB_2("flann") )#pragma comment( lib, CC_CVLIB("flann") )#pragma comment( lib, CC_CVLIB("gpu") )#pragma comment( lib, CC_CVLIB_2("highgui") )#pragma comment( lib, CC_CVLIB("highgui") )#pragma comment( lib, CC_CVLIB_2("imgcodecs") )#pragma comment( lib, CC_CVLIB_2("imgproc") )#pragma comment( lib, CC_CVLIB("imgproc") )#pragma comment( lib, CC_CVLIB("legacy") )#pragma comment( lib, CC_CVLIB_2("ml") )#pragma comment( lib, CC_CVLIB("ml") )#pragma comment( lib, CC_CVLIB("ocl") )#pragma comment( lib, CC_CVLIB("nonfree") )#pragma comment( lib, CC_CVLIB_2("objdetect") )#pragma comment( lib, CC_CVLIB("objdetect") )#pragma comment( lib, CC_CVLIB_2("photo") )#pragma comment( lib, CC_CVLIB("photo") )#pragma comment( lib, CC_CVLIB_2("shape") )#pragma comment( lib, CC_CVLIB_2("stitching") )#pragma comment( lib, CC_CVLIB("stitching") )#pragma comment( lib, CC_CVLIB_2("superres") )#pragma comment( lib, CC_CVLIB("superres") )#pragma comment( lib, CC_CVLIB_2("ts") )#pragma comment( lib, CC_CVLIB("ts") )#pragma comment( lib, CC_CVLIB_2("video") )#pragma comment( lib, CC_CVLIB("video") )#pragma comment( lib, CC_CVLIB_2("videoio") )#pragma comment( lib, CC_CVLIB_2("videostab") )#pragma comment( lib, CC_CVLIB("videostab") )#pragma comment(lib, CC_LIB("zlib"))#else#define CC_CVVERSION_ID CVAUX_STR(CV_VERSION_EPOCH) CVAUX_STR(CV_VERSION_MAJOR) CVAUX_STR(CV_VERSION_MINOR)//导入静态库依赖#pragma comment(lib, CC_LIB("IlmImf"))#pragma comment(lib, CC_LIB("libjasper"))#pragma comment(lib, CC_LIB("libjpeg"))#pragma comment(lib, CC_LIB("libpng"))#pragma comment(lib, CC_LIB("libtiff"))#pragma comment( lib, CC_CVLIB("calib3d") )#pragma comment( lib, CC_CVLIB("contrib") )#pragma comment( lib, CC_CVLIB("core") )#pragma comment( lib, CC_CVLIB("features2d") )#pragma comment( lib, CC_CVLIB("flann") )#pragma comment( lib, CC_CVLIB("gpu") )#pragma comment( lib, CC_CVLIB("highgui") )#pragma comment( lib, CC_CVLIB("imgproc") )#pragma comment( lib, CC_CVLIB("legacy") )#pragma comment( lib, CC_CVLIB("ml") )#pragma comment( lib, CC_CVLIB("ocl") )#pragma comment( lib, CC_CVLIB("nonfree") )#pragma comment( lib, CC_CVLIB("objdetect") )#pragma comment( lib, CC_CVLIB("photo") )#pragma comment( lib, CC_CVLIB("stitching") )#pragma comment( lib, CC_CVLIB("superres") )#pragma comment( lib, CC_CVLIB("ts") )#pragma comment( lib, CC_CVLIB("video") )#pragma comment( lib, CC_CVLIB("videostab") )#pragma comment(lib, CC_LIB("zlib"))#endif //CV_MAJOR_VERSION#endif


g.modify the .txt file name as  import_static_lib.h




h.back to the project ,

 


run codes: 




it‘s ok now


notes:

every time you new a project  you must set the properties as  use MFC in a Static Library,then you can run your codes。


if you want to Play video file,you must add the files:opencv_ffmpeg2410.dll and opencv_ffmpeg2410_64.dll to c:/windows/system32 

 





0 0
原创粉丝点击