Swift Framework with Opencv Dynamic Framework, Library Not Loaded

opencv framework not found in iOS

use following

#import "opencv2/opencv.hpp"

and in build settings -> compile as -> objective c++

Embed OpenCV framework inside another xCode project without linking

Yes. Clone(copy) opencv inside your project (headers and implementation)*, desclare the copied files inside your project and don't use any c/c++ include folder and any library linkage.

*implementations are in modules/.../src/

How to reduce the openCV framework size in iOS project

The opencv.framework you quoted is 500M, the volume of this project will increase by 500M, but the archive APP volume will not be 500M, because you only use some symbols, and the others are optimized by XCode. If you are concerned about this volume, it is recommended to download the complete opencv project from the official website and rebuild it according to your needs.
You only need 'core. Core functionality' and 'imgcodecs. Image file reading and writing'.

openCV 2.4.3 iOS framework compiler trouble recognising some c++ headers

I have everything working now. After having no joy with the pre-built iOS library available from openCV.org this is what I did...

  • compile openCV for iOS from a clone of the gitHub repository. Run build_framework.py (in the ios folder of the distribution), pointing to an output directory of your choosing. Be sure to have an up-to-date copy of CMake or you will trip over like I did.

  • Your output folder will end up with two subfolders, build and opencv2.framework. Drag the latter into your Xcode project

Add the following line in the project-Prefix.pch file

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif

(should go above the #ifdef __OBJC__ line)

That is sufficient to get most of openCV working. However it is a very good idea to avoid "objective-C++" (mixing your c++ code in the same files as your objective-C). To manage this you create a thin "wrapper" object (which will be obj-C++) to mediate between your obj-C classes and c++ code. The wrapper essentially has only two roles: to translate data formats (eg UIImage <-> cv::Mat), and to translate between obj-C methods and C++ function calls. See my answer to this question for details (and a github-hosted example project)

To get SURF (and SIFT) working requires a couple of additional steps, as SURF is somewhat deprecated due to licensing issues (it's been moved into nonfree which does not load automatically).

These includes need to be added in files where you are using SURF

#include <opencv2/nonfree/nonfree.hpp>
#include <opencv2/legacy/compat.hpp>

The code I am working with uses the C interfaces for SURF (eg cvExtractSURF), so we also need to add this line before calling these functions:

   cv::initModule_nonfree();

The other part of my question, how to force Xcode to compile as C++, was a bit of a red herring (there must have been something compatibility issue with the openCV build I was using) - and is no longer required for this solution. However the answer is first, to rename your .m files .mm (for objective-C++) or .cpp (for pure C++) … but if that doesn't work, you can force the issue in the file inspector by changing 'file type'.

update

You also need to take care that the C++ standard library is set correctly in any projects that use the openCV framework. Older versions of openCV (to.2.4.2) want libstdc++, newer (2.4.3+) expect libc++. Details here:

https://stackoverflow.com/a/14186883/1375695

update 2

openCV now installs with cocoaPods. To quote SebastienThiebaud

OpenCV is available on Cocoapods. Add one line in your Podfile: pod 'OpenCV'. Pretty easy.

"Pretty easy" ... given all our previous hassles, could be the understatement of [last] year...



Related Topics



Leave a reply



Submit