Opencv2 / opencv.hpp not found in Xcode
I created openCV to get opencv2.framework. I added this to my iOS xcode project by going to "build phase-> Link Binary With Libraries" and then trying to include "opencv2 / opencv.hpp" in my project. I get the error message "opencv2 / opencv.hpp" not found. But the file exists within. I tried to find a solution on the Internet, but nothing worked for me.
The file I'm trying to include it in is a .mm file. I did "compile sources as" objective-c ++. Any help would be great.
Took me 4 hours to figure this out. Here's how I got it to work: Along with the opencv card, add the following structures in the build steps:
Acceleration, AssetsLibrary, AVFoundation, CoreGraphics, CoreImage, CoreMedia, CoreVideo, QuartzCore, UIKit, Foundation.
Then, in the .pch file, add these lines before importing UIKit and Foundation:
#ifdef __cplusplus #import <opencv2/opencv.hpp> #endif What worked for me was very simple:
* NOTE DIFFERENCES OF IOS PROGRAMS vs. OS X
FOR IOS:
Put opencv download (for 3.0.0 it's just a drag and drop) in the project-specific Xcode folder. Then set the frame search paths to $ (PROJECT_DIR). The frame search path is located in the Build Settings section. No other paths need to be installed.
Finally, right-click on the navigator bar and click "Add Files To ..." to add it to the opencv library from the project folder.
FOR OSX:
check out the Tim tutorial: https://www.youtube.com/watch?v=OVSPfUmNyOw
In my case, symlinks to header files were corrupted. This was caused by the cloning of the following great example project:
https://github.com/BloodAxe/OpenCV-Tutorial
In a cloned project, header files are no longer available. After refinancing opencv2.framework from the official opensv ios download site ( OpenCV for iOS ), the headers were available again. Xcode should look like this:
Below is a screenshot of an Xcode project with broken headers. With broken header files, the xcode project looks like this:
I used openCV in my project, and it was impossible to implement it with cocoapods because the library version was too old, so I decided to implement it as a static library. create a folder in your project and add a library there, in the build settings find the library and framework search path and add the link to your openCV folder. It will work without errors. You should also add the openCV header file to prefixPatch .
More detailed instructions 100% work:
1) Download the framework from the official website: OpenCV
2) In the Project Directory, create a folder with the name: External_SDK
3) Place the Opencv structure inside this folder and drag it into the Xcode project (folder) with the target membership of your application (not App_test).
4) In the Xcode Project, find yourPrefixHeaderFileName.pch and add the following lines at the top of the file:
#ifdef __cplusplus #import <opencv2/opencv.hpp> #endif 5) after that you should import or include in the .h file, why include? because it is a CPP library. If you want to access the library using the import keyword, then you must do the following: #import <EXAMPLE>
6) In the build settings, find the library and framework search path and add the link to the EXTERNAL_SDK folder. To read the framework directly from your folder. Find and change ALWAYS_SEARCH_USER_PATHS = YES and HEADER_SEARCH_PATHS add $ (inherited) and / usr / include / FRAMEWORK _PATH
Hope this answer helps someone.
And the best practice is to call
#include <opencv2/highgui/highgui.hpp> #include <opencv2/core/core.hpp> Header files only.
Make sure that for the Build Settings for Target option, you have a search path in the Search Paths section set to the correct path to where your infrastructure is located in your directory. You can do this by clicking to the right of the Foreshortening search path in white space, click the + sign and add $ (PROJECT_DIR), then click + again and add $ (inherited). Make sure the structure is in your main directory for your project. This worked for me as I ran into the same issue.
Hope this helps!
In my experience, there is no need to add so many other frameworks. Instead, you need only opencv2 and add "#import" to prefixheader.pch
The fact is that you MUST set the correct search paths in the Map, as indicated above, if the framework opencv2 folder is not in the project directory.
Note. Do not set the wrong location in the Framework search path, as there are two "YourProjectName". Set 1st (applies to TARGETS) and not second (belongs to PROJECT). I made a mistake.
Here is my answer for that.
Environment: Xcode 8.1
Download page: http://opencv.org/downloads.html . Select any link for iOS.
Important step: when loading opencv2.framework you should use the ".zip" format, not the ".framework" format, then unzip it to opencv2.framework. This is strange, but it should work. Meanwhile, you should rename it to opencv2.framework, if unpacked - no.

just drag and drop the framework into your iOS project. No settings are required. You can refer to this for testing: www.youtube.com/watch?v=ywUBHqxwM5Q.
I ran into some problems when I switched to Target -> Build Phases -> Link Binary With Libraries. When I added opencv2.framework, my application will not start.
Instead, I just dragged the framework under the "Frameworks" directory in Xcode, and it worked. I have not changed anything.



