4

I am using the version of OpenCV for iPhone, and I have encountered a somewhat strange error. In using the stitcher, some of the imported headers are now complaining about an unmatched '{' on this line:

enum { NO, FEATHER, MULTI_BAND };

NO is a macro from objc.h which is defined as

#define NO              __objc_no

And the compiler is expecting a '}' to match the opening of the enum, even though there is one just a little later on. What is happening?

2
  • Ugh, Xcode does this when you try to import objC into a c file on your end of the spectrum. Check that your imports are correct, and that the files they're going into contain the proper extensions.
    – CodaFi
    Commented Jan 2, 2013 at 21:17
  • It looks right to me. Strange.
    – Jumhyn
    Commented Jan 3, 2013 at 1:43

4 Answers 4

11

I have been having the same problem for a long time and I have just now discovered a workaround. As you stated correctly it is a problem with definition of the NO-makro in UIKit. What you need to do is go to your .pch-file and replace

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

with

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#import <opencv2/stitching/detail/blenders.hpp>
#import <opencv2/stitching/detail/exposure_compensate.hpp>
#endif

So your resulting .pch should look something like this:

//
// Prefix header for all source files of the 'Project' target in the 'Project' project
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#import <opencv2/stitching/detail/blenders.hpp>
#import <opencv2/stitching/detail/exposure_compensate.hpp>
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif

This way the NO-enums in blenders.hpp and exposure_compensate.hpp are defined before the NO-makro in UIKit.

0
6

Swift: In your .mm file, you just have to undefine the 'NO' macro from UIKit before calling any OpenCV headers.

#import "OpenCVWrapper.h"
#undef NO
#import <opencv2/opencv.hpp>
1

I used a much simpler fix for Swift users.

In my .mm file I moved my .h import under #import<opencv2/opencv.hpp> .

Hope this helps!

0
1

I change the code -

//    enum { NO, FEATHER, MULTI_BAND };
    enum { NO_EXPOSURE_COMPENSATOR =  0, FEATHER, MULTI_BAND };

it works for me. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.