我找到了答案。
必须打开原来的openCV工程,并以静态库模式重新编译所有相关部分。
- 从以下时间开始为每个项目执行此操作
libjasper
并按字母顺序排列,直到opencv_video
。也做同样的事情zlib
project
- 对于每个项目,转到项目属性\配置属性\常规\配置类型并将其设置为静态库
- 现在重新编译这些项目。他们将创建许多大的 lib 文件(每个文件最多 10MB)。这些文件主要位于
modules
opencv 的目录。在针对 dll 进行编译时,您必须找到它们并复制到保留常规 lib 文件的目录中。现在是一个棘手的部分
- 与针对 dll 进行编译相比,您必须在代码中包含更多库
- 这是一个示例,您的代码应如下所示。抱歉,它的格式不好。可能是这个页面的 html bug:
#include "cv.h"
#include "highgui.h"
using namespace std;
using namespace cv;
// Directives to linker to include openCV lib files.
#ifndef STATIC_LIBRARY_LINK
// Linking against DLL. For each 'lib' file that appears below, final EXE will need a DLL.
// Core of openCV
#pragma comment(lib, "opencv_core220.lib")
#pragma comment(lib, "opencv_highgui220.lib")
#pragma comment(lib, "opencv_imgproc220.lib")
// Calibration and image matching
#pragma comment(lib, "opencv_flann220.lib")
#pragma comment(lib, "opencv_features2d220.lib")
#pragma comment(lib, "opencv_calib3d220.lib")
// Other libs that might be needed
/*#pragma comment(lib, "opencv_gpu220.lib")
#pragma comment(lib, "opencv_video220.lib")
#pragma comment(lib, "opencv_legacy220.lib")
#pragma comment(lib, "opencv_ml220.lib")
#pragma comment(lib, "opencv_objdetect220.lib")
#pragma comment(lib, "opencv_ffmpeg220.lib")
#pragma comment(lib, "opencv_contrib220.lib") */
#else
// Static linking. No DLL's would be required but EXE file will be bigger
// and linking in debug mode might produce many warnings since *.pdb are not always
// present with the lib files
// Core of openCV. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_core.lib")
#pragma comment(lib, "opencv_highgui.lib")
#pragma comment(lib, "opencv_imgproc.lib")
// Calibration and image matching. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_flann.lib")
#pragma comment(lib, "opencv_features2d.lib")
#pragma comment(lib, "opencv_calib3d.lib")
// Image I/O auxillary libraries. Must be compiled as lib and not as dll's
#pragma comment(lib, "libtiff.lib")
#pragma comment(lib, "libpng.lib")
#pragma comment(lib, "zlib.lib")
#pragma comment(lib, "libjasper.lib")
#pragma comment(lib, "libjpeg.lib")
// OpenCV linear algebra methods. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_lapack.lib")
// Auxillary libs, found in visual studio microsoft sdk
#pragma comment(lib, "vfw32.lib")
#pragma comment( lib, "comctl32.lib" )
//#pragma comment(lib, "window_w32.lib") // Not needed
#endif
int main(void){
// Your code here
return 0;
}