There’s an article describing how to do this here, that seems to have worked for other people but it does not compile for me.
Here’s a copy of the .h file that was used:
//
// NSImage+OpenCV.h
//
#import <AppKit/AppKit.h>
@interface NSImage (NSImage_OpenCV) {
}
+(NSImage*)imageWithCVMat:(const cv::Mat&)cvMat;
-(id)initWithCVMat:(const cv::Mat&)cvMat;
@property(nonatomic, readonly) cv::Mat CVMat;
@property(nonatomic, readonly) cv::Mat CVGrayscaleMat;
@end
I’m on Xcode 4.4, using openCV 2.4.2. The compiler errors I’m getting for the header file are 4x of the following:
Semantic issue: Use of undeclared identifier 'cv'
This error seems rather obvious…the header file does not define what a cv::Mat is.
So I took a guess from looking at the OpenCV 2.4 tutorial, that I needed to add
#include <opencv2/core/core.hpp>
This generated 20 other errors, where the compiler was complaining about the core.hpp file.
The first of which says:
Semantic issue: Non-const static data member must be initialized out of line
So my question is what am I doing wrong? How do I get this code to work?
Another stackoverflow Q&A (link: How to include OpenCV in Cocoa Application?) had the missing piece on the undefined symbols.
To summarize:
Normally, it looks like:
Instead, the file should be changed to look like:
So in the case of any *.cpp file, the opencv header gets added automatically. In the case of any *.m file, the Cocoa headers are added. And in the special case of *.mm files, they BOTH get added, and in the correct order.
Kudos to Ian Charnas and user671435 for figuring this out.