Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv2/opencv.hpp file not found in Xcode

Tags:

xcode

ios

opencv

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.

like image 802
Anirudh GP Avatar asked Dec 23 '15 06:12

Anirudh GP


5 Answers

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

like image 156
Ekkelenkamp Avatar answered Nov 02 '22 07:11

Ekkelenkamp


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. ;-)

like image 23
Alex Reche Martinez Avatar answered Nov 02 '22 08:11

Alex Reche Martinez


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
like image 40
Anirudh GP Avatar answered Nov 02 '22 06:11

Anirudh GP


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

like image 11
N.Atanasov Avatar answered Nov 02 '22 08:11

N.Atanasov


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!

like image 2
Evan Bauer Avatar answered Nov 02 '22 08:11

Evan Bauer