How to compile OpenCV with extra modules on OS X?

为君一笑 提交于 2021-01-28 00:14:00

问题


I've previously compiled OpenCV 3.0 successfully following this guide, which essentially consists of the following steps:

  • Download all the prerequisites (XCode, Command Line Tools, CMake and OpenCV source)
  • Build static libs by configuring CMake (via gui) with:
    • Uncheck BUILD_SHARED_LIBS
    • Uncheck BUILD_TESTS
    • Add an SDK path to CMAKE_OSX_SYSROOT (if it matters, I used /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk).
    • Add x86_64 to CMAKE_OSX_ARCHITECTURES (emphasis mine, this seems to be the issue, I'm sure I've followed this step)
    • Uncheck WITH_1394
    • Uncheck WITH_FFMPEG
  • Configure and generate via CMake, then make and sudo make install from the CLI.

All of the above alone works fine.


I'm now looking to compile OpenCV with the extra modules. According to their read-me it should be as simple as filling out OPENCV_EXTRA_MODULES_PATH to <opencv_contrib>/modules in CMake and then building as usual.

I followed the steps outlined above with the added parameter and building OpenCV succeeds, however, when trying to use one of the extra modules in a program (namely cv::ximgproc::createStructuredEdgeDetection, if it matters), I'm getting the following error when compiling:

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)

I've included the header which should include the above:

#include <opencv2/ximgproc.hpp>

I'm compiling via XCode, where I've set an additional header search path of /usr/local/include and a library search path of /usr/local/lib for the project, am I missing something here?

Standard OpenCV functionality works fine.

What could be the issue and how would I go about solving it?


回答1:


OpenCV contrib modules are built correctly.

You just need to add the contrib libs to your dependencies, in this case adding: -lopencv_ximgproc.


All available libs can be found under <OPENCV_DIR>/install/ folder. E.g. in my 32bit vc12 static build are in<OPENCV_DIR>/install/x86/vc12/staticlib folder.



来源:https://stackoverflow.com/questions/33157592/how-to-compile-opencv-with-extra-modules-on-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!