Swift 4 - OpenCV 3.2 on Xcode 9.0 beta 2

Viewed 2296

I'm actualy trying to use OpenCV with ARKit to build an AR app. For the past 6 hours I tried everything to install OpenCV on my Swift project but that seems impossible.
I followed this tutorial on Medium and I ended up with 3 new files with the framework : OpenCVWrapper.h and OpenCVWrapper.mm for the wrapper and LittleFarm-Bridging-Header.h for the bridging header, here is the code :

OpenCVWrapper.h

#import <Foundation/Foundation.h>
#import <stdio.h>
@interface OpenCVWrapper : NSObject

- (void) isItWorking;
@end

OpenCVWrapper.mm

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

@implementation OpenCVWrapper

    using namespace std;
    - (void) isItWorking {
        printf("Hey");
    }
    @end

LittleFarm-Bridging-Header.h

#import "OpenCVWrapper.h"

But then I get this error : 'opencv2/opencv.hpp' file not found
I tried to figure what was the problem and I set Framework_Search_Path to $(PROJECT_DIR). That doesn't change anything and if I tried to comment the related line I get this error :
ld: framework not found opencv2
clang: error: linker command failed with exit code 1 (use -v to see invocation)


Edit : In Build Phase > Link Binary with Librairies the framework opencv2 is here.

Thanks in advance for the help !

2 Answers

If someone would like to use the current version or anything newer than 3.1.0.1 of OpenCV with XCode, this workaround helps. To ignore the documentation warnings this may also help.

Amayatsky wrote:

I have moved #import <opencv2/opencv.hpp> above all other imports as suggested and that did the trick.

Related