11
votes

I have built openCV to get opencv2.framework. I added this to my xcode iOS project by going to "build phases->Link Binary With Libraries", then tried to include "opencv2/opencv.hpp" in my project. I get the error "opencv2/opencv.hpp" not found. But the file exists in the framework. I have tried to find a solution online but nothing has worked for me.

The file I'm trying to include it in is a .mm file. I have made "compile sources as" objective-c++. Any help would be great.

9
Just try to add include "opencv.hpp". its working?Ekta Padaliya
Nope. "opencv.hpp" file not foundAnirudh GP
some time when we drag and drop frame work in to app that may cause some problmes so do one thing. First remove opencv2.framework from your project. Now right click on project -> click on add file to project -> select opencv2.framework.Ekta Padaliya
@AnirudhGP how did build the opencv framework? I have been downloading it from their site and then dragging and dropping the download into my project. is that right?KellysOnTop23
as of Mar 2016(Obj-C), just download the framework from opencv.org/downloads.html , then you may need to alter the .pch file with the following. #ifdef __cplusplus //#import <opencv2/opencv.hpp> #include <opencv2/opencv.hpp> #endif _______________Matthew Ferguson

9 Answers

11
votes

What worked for me was very simple:

*NOTE THE DIFFERENCE FOR IOS vs. OS X PROJECTS

FOR IOS:

Put the opencv download (for 3.0.0 it is just a drag and drop kind of thing) into the project specific Xcode folder. Then set the Frame Search Paths to $(PROJECT_DIR). The Frame Search Path is located under the Build Settings. No other paths need to be set.

Lastly, right click in the navigator pane and click "Add Files to..." in order to add in the opencv library from the project folder.

FOR OSX:

check out Tim's tutorial: https://www.youtube.com/watch?v=OVSPfUmNyOw

7
votes

I solve the problem by adding to the FRAMEWORK_SEARCH_PATHS the absolute path were I had the framework I needed to use:

Edition of the Framework Search Path

You should use your own path obviously. ;-)

5
votes

Took me 4 hours to figure this out. This is how I got this to work : Along with the opencv framework add the following frameworks in the build phases:

Accelerate, AssetsLibrary, AVFoundation , CoreGraphics , CoreImage , CoreMedia , CoreVideo , QuartzCore , UIKit , Foundation.

Then, in the .pch file add these lines before UIKit and Foundation imports :

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

In my case the symbolic links to the header files were broken. This was caused by cloning the following great example project:

https://github.com/BloodAxe/OpenCV-Tutorial

In the cloned project, the header files were not reachable anymore. After reimporting the opencv2.framework from the official opencv ios download site (OpenCV for iOS), the headers were available again. XCode should look as follows:

XCode opencv headers

The following is a screenshot of a Xcode project with broken headers. With broken header files, the xcode project looks as follows:

XCoe with broken opencv headers

2
votes

Make sure in Build Settings for the Target, you have the Framework Search Path in the Search Paths section set to the correct path to where your framework is located in your directory. You can do this by clicking to the right of Framework Search Path in the white space, click the + sign and add $(PROJECT_DIR) then click + again and add $(inherited). Make sure the framework is located in your main directory for your project at hand. This worked for me, as I encountered the same problem.

Hope this helps!

1
votes

I used openCV in my project and implementing it with cocoapods was impossible because version of library was too old, so i decided to implement it as static library. create folder in your project and add library there, in build settings find library and framework search path and add link to your openCV folder. It will work without any error. Also you should add openCV header file in prefixPatch.

More Detail Instruction 100% Works:

1) Download framework from official website: OpenCV

2) In Project Directory create folder named: External_SDK

3) Put Opencv framework inside this folder and drag&drop it in Xcode Project (Folder) with Target Membership of your App (Not App_test).

4) In Xcode Project search for yourPrefixHeaderFileName.pch and in the top of the file add this lines:

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

5) after that you should import or include it in .h file, why include? because it's CPP library. If you want to access library with import keywoard than you should do like this: #import <EXAMPLE>

6) In build settings search for library and framework search path and add link to your EXTERNAL_SDK folder. To read framework directly from your folder. Find and change ALWAYS_SEARCH_USER_PATHS = YES and in HEADER_SEARCH_PATHS add $(inherited) and /usr/include/FRAMEWORK_PATH

Hope this answer will help someone.

And the best practice is to call

#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>

Only header files.

0
votes

From my experience, it is not necessary to add so many other frameworks. Instead, only need opencv2 and add "#import " in prefixheader.pch

The thing is that MUST set correct Framework Search Paths as mentioned above unless opencv2 framework folder is in your project directory.

Notice: don't set wrong location in Framework Search Paths as there are two "YourProjectName". Set the 1st one (belongs to TARGETS), not the 2nd one(belongs to PROJECT). I made the mistake.

0
votes

Here is my answer for this.

  1. Environment: XCode 8.1

  2. Download page: http://opencv.org/downloads.html. Choose any link for iOS.

  3. Important step: while downloading opencv2.framework, you must use ".zip" format, not ".framework" format, afterwards, unzip it to opencv2.framework. It is weird, but it should work. Meanwhile, you have to rename it to opencv2.framework if the unzipped one is not. enter image description here

  4. just drag and drop the framework to your iOS project. No any settings are required. You could refer to this for testing : www.youtube.com/watch?v=ywUBHqxwM5Q.

0
votes

I ran into some issues when I went to Target-->Build Phases-->Link Binary With Libraries. When I added opencv2.framework from there, my app would not launch.

Instead, I just dragged and dropped the framework under the directory "Frameworks" in XCode and that worked. I didn't change anything else.