在 Mac OSX 上使用 Xcode4 部署和分发 OpenCV 应用程序

发布于 2024-11-26 12:30:27 字数 127 浏览 0 评论 0原文

我正在开发 OpenCV 应用程序,我的问题是如何在非开发机器(未安装 OpenCV 的机器)上部署和分发该应用程序?

我在 Mac OS X Lion 上使用 Xcode4 和 OpenCV 2.2。

谢谢

I'm working on an OpenCV application and my question is how can I deploy and distribute the application on non-development-machines, machines where OpenCV isn't installed?

I'm using Xcode4 on Mac OS X Lion with OpenCV 2.2.

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吖咩 2024-12-03 12:30:27

这只是部分答案,因为我还没有弄清楚如何使用 OpenCV 库来做到这一点。 (弄清楚了。请参阅下面的更新。)但我已经用其他库完成了它(SM2DGraphView)。

需要执行三件事:

  1. 您需要将程序使用的 OpenCV 库复制到应用程序包中。为此(无论如何,在 Xcode 3 中),请向您的目标添加复制文件构建阶段。将库文件从 Xcode 的文件列表拖到构建阶段。双击“复制文件”项并将目标设置为“框架”。

    请注意,您需要确保 Xcode 项目中包含的库是库文件,而不是库文件的符号链接。否则,只会将符号链接复制到您的应用程序包中。

  2. OpenCV框架文件的安装路径需要设置为@executable_path/../Framework。如果框架是在 Xcode 中构建的,您可以在项目设置中执行此操作。由于 OpenCV 不是在 Xcode 中构建的,因此您需要在事后使用 install_name_tool 命令行程序来完成此操作:install_name_tool -id @executable_path/../Frameworks libopencv_imgproc.2.3.1.dylib。您应该能够在目标中的运行脚本构建阶段进行设置。

  3. 可执行文件需要在包的 Frameworks 目录中查找库。这就是我目前陷入困境的地方。

更新

我找到了正确的 install_name_tool 命令来让程序查看库(以及让库查看其他库)。 用于部署 OS X 程序的 Qt 页面 上的信息是钥匙。

我在程序的 Contents/MacOS 目录中的可执行文件上运行了 otool -L 并看到了这个[删除了不相关的行]:

lib/libopencv_core.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_imgproc.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_highgui.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)

所以我使用这些命令(在 Contents/MacOS 目录中时)来获取程序在正确的位置查找库:

install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib CocoaCVTest 
install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib CocoaCVTest 
install_name_tool -change lib/libopencv_highgui.2.3.dylib @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib CocoaCVTest 

然后我更改为 Contents/Frameworks 目录,并使用这些命令告诉库它们的安装位置:

install_name_tool -id @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_core.2.3.1.dylib
install_name_tool -id @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_imgproc.2.3.1.dylib
install_name_tool -id @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib libopencv_highgui.2.3.1.dylib

现在需要告诉 imgproc 库在哪里可以找到核心库和 highgui需要是告诉在哪里可以找到 core 和 imgproc:

install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_imgproc.2.3.1.dylib
install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_highgui.2.3.1.dylib 
install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_highgui.2.3.1.dylib 

我仍然遇到一个问题,highgui 在 /opt/local/bin 中寻找大量库,但我相当有信心问题的 OpenCV 部分已经解决。现在我只需要将所有这些命令放入 Xcode 的构建阶段即可。

This is only a partial answer because I also haven't yet figured out how to do this with the OpenCV libraries. (Figured it out. See update below.) But I have done it with other libraries (SM2DGraphView).

There are three things that need to happen:

  1. You need to copy the OpenCV libraries that your program uses into the application bundle. To do that (in Xcode 3, anyway), add a Copy Files build phase to your target. Drag the library files from Xcode's file list onto the build phase. Double-click the Copy Files item and set the destination to Frameworks.

    Note that you need to make sure that the library you include in your Xcode project is a library file and not a symlink to a library file. Otherwise only the symlink will be copied to your application bundle.

  2. The install path of the OpenCV framework files needs to be set to @executable_path/../Framework. If the framework was being built in Xcode, you'd do this in the project settings. Since OpenCV is not being built in Xcode you need to do it after the fact with the install_name_tool command line program: install_name_tool -id @executable_path/../Frameworks libopencv_imgproc.2.3.1.dylib. You should be able to set this up in a Run Script build phase in your target.

  3. The executable needs to find the library in the bundle's Frameworks directory. This is where I'm currently stuck.

Update

I found the correct install_name_tool commands to get the program to see the libraries (and the libraries to see the other libraries). The information on the Qt page for deploying OS X programs was the key.

I ran otool -L on the executable file in my program's Contents/MacOS directory and saw this [non-relevant lines removed]:

lib/libopencv_core.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_imgproc.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)
lib/libopencv_highgui.2.3.dylib (compatibility version 2.3.0, current version 2.3.1)

So I used these commands (while in the Contents/MacOS directory) to get the program to look in the right place for the libraries:

install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib CocoaCVTest 
install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib CocoaCVTest 
install_name_tool -change lib/libopencv_highgui.2.3.dylib @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib CocoaCVTest 

Then I changed to the Contents/Frameworks directory and used these commands to tell the libraries where they were installed:

install_name_tool -id @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_core.2.3.1.dylib
install_name_tool -id @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_imgproc.2.3.1.dylib
install_name_tool -id @executable_path/../Frameworks/libopencv_highgui.2.3.1.dylib libopencv_highgui.2.3.1.dylib

Now the imgproc library needs to be told where to find the core library and highgui needs to be told where to find core and imgproc:

install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_imgproc.2.3.1.dylib
install_name_tool -change lib/libopencv_core.2.3.dylib @executable_path/../Frameworks/libopencv_core.2.3.1.dylib libopencv_highgui.2.3.1.dylib 
install_name_tool -change lib/libopencv_imgproc.2.3.dylib @executable_path/../Frameworks/libopencv_imgproc.2.3.1.dylib libopencv_highgui.2.3.1.dylib 

I'm still running into an issue where highgui is looking for a lot of libraries in /opt/local/bin but I'm fairly confident that the OpenCV part of the problem is solved. Now I just need to get all these commands into a build phase in Xcode.

你不是我要的菜∠ 2024-12-03 12:30:27

我建议是使用跨平台编译构建器(如改进的自动工具)。一个非常常见的是 CMake,它不太容易处理,但也不那么困难,不仅是常见的,它被 OpenCV 使用...

  • 1)在您的开发机器上编写您的应用程序并编写一个 Cmake(不要不要忘记编写一个使用 OpenCV Cmake 的部分)

  • 2)提供您的 cmake 文件和 opencv 库到非开发机器

  • 3) 使用CMake脚本在目标平台上构建应用程序,如果你正确编写它,它可以构建opencv(使用自己的OpenCV Cmake),并构建您的应用程序(使用您编写的)

如果您想更进一步,您可以创建一个安装向导或使用 CPack 的包来自动化一切操作。

这是您可以下载它的链接

Julien,

What i would advise is to use a cross platform compilation builder (like an improved autotool). A very common one is CMake which is not so easy to handle but not so difficult, not only a common one, it is used by OpenCV...

  • 1) Write your application on your development machine and write a Cmake (don't forget to write a part to use the OpenCV Cmake)

  • 2) Provide your cmake files and the opencv library to the non-development machine

  • 3) Build with CMake script the application on the target platform, if you wrote it correctly it can build opencv (using the own OpenCV Cmake), and build your application (with the one you wrote)

If you want to go further, you can create an install wizard or a package with CPack in order to automatize everyting.

Here is the link where you can download it

Julien,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文