OpenCV 2.4.3 iOS source compiler does not recognize some C ++ headers

openCV 2.4.3 / Xcode 4.5.2 / mac osx 10.8.2

I am trying to open openCV with iOS. I am trying to use the predefined 2.4.3 structure with openCV.org. However, I get the following xcode project building errors, which suggest that the compiler does not know that it is dealing with C ++, for example

#include <list> !'list' file not found namespace cv !unknown type name 'namespace' 

This is only similar to the following header files:
"Opencv2 / nonfree / features2d.hpp"
"Opencv2 / not free / nonfree.hpp"
"opencv2 / video / video.hpp"

If I don't include these three files in opencv.hpp (or somewhere else), I seem to be able to compile and use openCV ok. The trouble is that I need useless files, as I am experimenting with SURF, which has recently been ported to insecure.

This is a really twofold question (sorry ;-)

  • How can I convince the compiler that these are C ++ headers?
  • which contains the headers, do I need to use SURF?

Update

I cloned the openCV git repository and created a new structure from it. This approach did not work before, but today I realized that I did not use the current version of CMAKE. I used CMAKE 2.8.2 and this would not be able to create opencv for ios. The current version of CMAKE 2.8.10 builds it without any problems (it is required that the object lesson be in accordance with documents that say that CMAKE min. V2.8.8 is required).

Now, when I add this current build of the opencv framework in the Xcode project, I can enable the 2d functions, as well as without restrictions, and build smoothly. The only problem remains with one heading: video/background_segm.hpp , which still gives:

 #include <list> !'list' file not found 

If I comment on this line, I get an error on the following line:

 namespace cv !unknown type name 'namespace' 

It seems obvious that the compiler does not recognize this as a C ++ header, although it is suffixed with .hpp .

In opencv2/video/video.hpp if I remove

 #include "opencv2/video/background_segm.hpp" 

I can also build using video.hpp (although, in my opinion, this would be unsuitable in practice).

Unfortunately, I still can't get SURF to work. When I run the project, it crashes with this error:

OpenCV error: function / function not implemented (OpenCV was created without SURF support)

This works in legacy/features2d.cpp :

  Ptr<Feature2D> surf = Algorithm::create<Feature2D>("Feature2D.SURF"); if( surf.empty() ) CV_Error(CV_StsNotImplemented, "OpenCV was built without SURF support"); 

Questions remain ...

  • How can I convince the compiler that background_segm.hpp is a legitimate C ++ header?
  • How to enable support for SURF?
+11
c ++ ios xcode opencv
Dec 16
source share
2 answers

Everything works for me now. After I didn't get the joy of the iOS built-in library available from openCV.org, this is what I did ...

  • compile openCV for iOS from the clone of the gitHub repository. Run build_framework.py (in the ios folder of the distribution), pointing to the output directory of your choice. Make sure you have an updated copy of CMake or you will travel like me.

  • There will be two subfolders in the output folder, build and opencv2.framework . Drag the last one into your Xcode project

Add the following line to the project-Prefix.pch

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

(should go above the line #ifdef __OBJC__ )

This is enough to get most of the work of openCV. However, it is highly recommended that you 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 objects and C ++ code. The wrapper essentially has only two roles: translate data formats (for example, UIImage ↔ cv :: Mat) and translate between obj-C methods and C ++ function calls. See my answer to this question for details (and an example project with github support)

SURF (and SIFT) requires a few extra steps to work, as SURF is a little dated due to licensing issues (this has moved to nonfree , which does not load automatically).

These include the need to add to files where you use SURF

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

The code I'm using uses the C interfaces for SURF (e.g. cvExtractSURF ), so we also need to add this line before calling these functions:

  cv::initModule_nonfree(); 

Another part of my question on how to get Xcode to compile as C ++ was a bit of a red herring (there must have been a compatibility issue with the openCV construct I used) - and no solution is needed for this anymore. However, you first need to rename your .m files .mm (for objective-C ++) or .cpp (for pure C ++) ... but if this does not work, you can force the problem in the file inspector by changing the 'file type '.

update

You also need to make sure that the standard C ++ library is properly configured in any projects that use the openCV infrastructure. Older versions of openCV (to.2.4.2) want libstdc++ , newer (2.4.3+) to expect libc++ . Details here:

stack overflow

update 2

openCV is now installed using cocoaPods. To quote SebastienThiebaud

OpenCV is available on Cocoapods. Add one line to your subfile: pod 'OpenCV'. Pretty easy.

"Pretty easy" ... given all our previous troubles, it might be an understatement of [last] year ...

+10
Jan 04 '13 at 5:53
source share

The openCV implementation class simply adds .m to .mm as the implementation file.

 #import <UIKit/UIKit.h> #import <opencv2/opencv.hpp> @interface ViewController : UIViewController @end 

enter image description here .mm run the file in the C ++ compiler in iOS so that it does not display an error.

+1
Jan 03 '14 at 10:59
source share



All Articles