Reputation: 7863
I downloaded the latest pre-built opencv2.framework from the OpenCV SourceForge page. then in Xcode6-Beta3, I added opencv2.framework as a required linked framework under the "General" tab of my Swift project settings:
This is the structure of the framework after the framework is added to the project:
If this was a Objective-C project I could add the following import statement:
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
In my ViewController.swift file, if I do something similar I get a "no such module" error:
I tried the following variations that result in an error:
import opencv2/opencv.hpp
import opencv2/opencv
import opencv
import "opencv2/opencv.hpp"
import <opencv2/opencv>
What is the correct way to import opencv in to my Swift project?
Upvotes: 8
Views: 10309
Reputation: 10978
It's easiest if you start with a simple project all ready to compile and run out of the box.
This xcode project works with Swift, XCode 6.1, OpenCV 2, and is MIT licensed: http://whitneyland.com/2014/10/opencv-swift.html
Here's one I haven't tried yet but there are so few still it's worth looking at: https://github.com/foundry/OpenCVSwiftStitch
Upvotes: 3
Reputation: 3031
You will need to create a bridge from C++ to Objective C or plain C. After that, you will need to include/import the bridge's header into an "Objective-C Bridging Header", which Xcode should have generated when you added a Swift source file in an existing project.
Upvotes: 2