I have compiled openCV 3.1
with contrib modules using cmake gui following this link. The files have been generated but how do I use it in my ios project? Is there a way to create the opencv.framework file or do I just import the whole built folder into my XCode project.
-
Why do you need something like that? You already have opencv.framework compiled– Ispas ClaudiuJun 16, 2017 at 8:38
-
I need the modules xfeatures2d and xphoto to follow along a textbook– Rgfvfk IffJun 16, 2017 at 8:42
2 Answers
Maybe it would be simplest to use command line instead of using CMakeGUI to build openCV with additional modules. CMake must be installed, of course.
Create somewhere in a place suitable for you a new folder
>mkdir ~/your_open_cv_dir
>
>cd ~/your_open_cv_dir
>
>git clone https://github.com/opencv/opencv.git
If your need extra modules clone their sources too
>git clone https://github.com/opencv/opencv_contrib.git
Your your_open_cv_dir can have inside 2 folders, opencv and opencv_contrib
Make a symbolic link for Xcode to let the OpenCV build scripts find the compiler, header files etc.
>cd /
>
>sudo ln -s /Applications/Xcode.app/Contents/Developer Developer
Build OpenCV framework:
>cd ~/your_open_cv_dir
>
>python opencv/platforms/ios/build_framework.py ios
In case you need extended version of OpenCV build it with extra modules
>python opencv/platforms/ios/build_framework.py ios --contrib opencv_contrib
-
To add onto @Dimitry 's answer, specifying which modules to load will reduce any errors you may encounter in xcode and reduce the time it takes to build. For example, you can exclude moduls using the --without modulename argument. Last, the
opencv_contrib
argument is a relative path to the opencv_contrib– jsibsMay 1, 2020 at 4:33
- Look for opencv2.framework in opencv/platforms/ios/ios/opencv2.framework (if you followed the cmake instructions correctly, the framework should have been built there). If you built opencv_contrib separately, the framework will be under opencv/platforms/ios/ios_contrib/opencv2.framework.
- Drag opencv2.framework into your Xcode project. Make sure you check "copy items if needed".
- In "Build Phases", under "Link Binary with Libraries", add opencv2.framework. This might do the trick. You can check by importing an OpenCV header in one of your Objective-C++ files and seeing if Xcode can find it. If not, follow the next steps to specify a header search path.
- In your project's "Build Settings", add $(PROJECT_DIR) to "Framework Search Paths", "Header Search Paths", and "Library Search Paths".
- Now you can import OpenCV header files (.hpp files) in your Objective-C++ code.