如何在 OS X 上编译带有额外模块的 OpenCV?

How to compile OpenCV with extra modules on OS X?

我之前已经按照this guide成功编译了OpenCV 3.0,主要包括以下步骤:

以上所有方法都可以正常工作。


我现在想用 the extra modules 编译 OpenCV。根据他们的read-me,它应该像在 CMake 中填写 OPENCV_EXTRA_MODULES_PATH<opencv_contrib>/modules 一样简单,然后像往常一样构建。

我按照上面列出的步骤添加了参数并成功构建了 OpenCV,但是,当尝试在程序中使用一个额外模块时(即 cv::ximgproc::createStructuredEdgeDetection,如果重要的话),我编译时出现以下错误:

Undefined symbols for architecture x86_64:
"cv::ximgproc::createStructuredEdgeDetection(cv::String const&, cv::Ptr<cv::ximgproc::RFFeatureGetter const>)", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我已经包括了 header 应该包括以上内容:

#include <opencv2/ximgproc.hpp>

我正在通过 XCode 进行编译,我在其中为项目设置了 /usr/local/include 的附加 header 搜索路径和 /usr/local/lib 的库搜索路径,我在这里遗漏了什么吗?

标准 OpenCV 功能运行良好。

可能是什么问题,我将如何解决它?

OpenCV contrib 模块构建正确。

您只需要将 contrib 库添加到您的依赖项中,在本例中添加:-lopencv_ximgproc.


所有可用的库都可以在 <OPENCV_DIR>/install/ 文件夹下找到。 例如。在我的 32 位 vc12 静态构建中,在 <OPENCV_DIR>/install/x86/vc12/staticlib 文件夹中。