如何嵌入openCV Dll在可执行文件 [英] How to embedd openCV Dll's in Executable

查看:308
本文介绍了如何嵌入openCV Dll在可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个图像匹配工具(控制台应用程序,没有gui或windows),使用openCV。
我想把我的EXE文件到另一台计算机,但它要求opencv dll(opencv_core220.dll,opencv_highgui220.dll,...)

I wrote an image matching tool (console application, without gui or windows), using openCV. I want to port my EXE file to another computer but it asks for opencv dlls (opencv_core220.dll, opencv_highgui220.dll, ...)

我的问题是怎么做的。我看到两种方法都是好的:

My question is how to do it. I see two ways any of them is good:


  1. 将opencv重新编译为静态库(.lib而不是.dll)。那没有工作。我收到10个链接器错误关于cap_vfw.obj

  2. 如果可能,如何合并/嵌入DLL到exe文件。

我试图使用 ILMerge ,但它不工作(错误:coul'd不从a.exe文件加载程序集),因为它是为.Net设计的

I tried to use ILMerge, but it doesnt work (Error: coul'd not load assembly from a.exe file) since it is designed for .Net only

PS - 我使用visual studio 2005,在windows,c ++编译器,openCV 2.2

P.S. - I am using visual studio 2005, on windows, c++ compiler, openCV 2.2

推荐答案


您必须打开原始的openCV项目并在静态库模式下重新编译所有相关部分。

I found an answer. You must open the original openCV project and recompile all the relevant parts in static library mode.


  • libjasper 开始,按字母顺序为 opencv_video 。也对 zlib 项目也这样做

  • 对于每个项目,转到项目属性\configuration properties\general\configuration type并将其设置为静态库

  • 现在重新编译这些项目。他们将创建许多大型的lib文件(高达10MB)。这些文件主要位于opencv的 modules 目录中。你必须找到他们,并复制到目录,当你保存你的常规lib文件,当编译对dll的。现在是一个棘手的部分

  • 您必须在代码中包含更多的库,而不是编译dll的时候

  • 应该看起来像这样。很抱歉,格式不正确。可能是此页面的HTML错误:

  • Do it for each project starting from libjasper and alphabetically until opencv_video. Also do the same for zlib project
  • For each project, go to project properties\configuration properties\general\configuration type and set it to static library
  • Now recompile those projects. They will create many large lib files (of up to 10MB) each. Those files are located mainly in modules directory of opencv. You must find them and copy to the directory when you keep your regular lib files when compiling against dll's. Now is a tricky part
  • You have to include in your code more libraries, than when you compile against dll's
  • Here is an example what your code should look like this. Sorry that it is not formatted well. Probably html bugs of this page:
#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;
    }

这篇关于如何嵌入openCV Dll在可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆