Rgfvfk Iff
Rgfvfk Iff

Reputation: 1609

How to build opencv in ios

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.

Upvotes: 3

Views: 4685

Answers (2)

Dmitry A.
Dmitry A.

Reputation: 598

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

Upvotes: 5

Berthy
Berthy

Reputation: 11

  1. 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.
  2. Drag opencv2.framework into your Xcode project. Make sure you check "copy items if needed".
  3. 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.
  4. In your project's "Build Settings", add $(PROJECT_DIR) to "Framework Search Paths", "Header Search Paths", and "Library Search Paths".
  5. Now you can import OpenCV header files (.hpp files) in your Objective-C++ code.

Upvotes: 1

Related Questions