一、下载OpenCV 的 ios-framework,我用了opencv-3.2.0-ios-framework版本,官方下载传送门:http://opencv.org/opencv-3-2.html
二、新建项目,加入相关frmework,如下:
libc++.tbd
AVFoundation.framework
CoreImage.framework
CoreGraphics.framework
QuartzCore.framework
Accelerate.framework
如果要使用摄像头做视频处理,还需要添加以下三个依赖库:
CoreVideo.framework
CoreMedia.framework
AssetsLibrary.framework
未添加相应依赖库报错:

三、在需要的地方引入:
import <opencv2/opencv.hpp>(不建议),
如有引用问题,尝试引入(以下需要的对应的头文件,可直接在framework中寻找对应头文件引入):
import <opencv2/videoio/cap_ios.h>
include "opencv2/video/tracking.hpp"
include <stdio.h>
include "opencv2/highgui/highgui.hpp"
include "opencv2/imgproc/imgproc.hpp"
include "opencv2/core/core.hpp"
include <tuple>
using namespace cv;
using namespace std;
这里需要注意几点:
1.需要将.m文件的Type设置为Objective-C++ Source,否则编译报错。如图:

2.如果当前引用opencv的类被其他类引用,那么这个类的.m文件的Type也需要设置为Objective-C++ Source,否则编译报错。如图:

3.opencv API要在苹果API之前引入,否则可能会导致一些定义上的冲突
网友评论