標(biāo)簽:iOS OpenCV
最近嘗試在 iOS 上使用 OpenCV,網(wǎng)上的資料比較少,且大多資料和源碼都已經(jīng)無(wú)用,來(lái)回折騰了好久才跑通一個(gè)基本的 Demo 程序,記錄下來(lái)留作筆記。
iOS 中導(dǎo)入 OpenCV
最早嘗試 OpenCV 官網(wǎng)上的介紹的下載源碼編譯生成 framework、或者直接從官網(wǎng)上下載 framework 導(dǎo)入工程,都無(wú)法使用。同樣網(wǎng)上介紹直接使用 CocoaPods 飛速導(dǎo)入 OpenCV 也無(wú)法使用。
最終在 github 上查找開(kāi)源的 iOS OpenCV 源碼,找到一個(gè)可以運(yùn)行使用的項(xiàng)目 EasyPR-iOS,導(dǎo)入了其中的opencv2.framework,才成功過(guò)編譯通過(guò)。
項(xiàng)目環(huán)境配置
開(kāi)發(fā)環(huán)境:XCode8.2
1.項(xiàng)目中導(dǎo)入相關(guān) frameworks
ImageIO.framework
QuartzCore.framework
CoreVideo.framework
CoreImage.framework
CoreGraphics.framework
AVFoundation.framework
AssetsLibrary.framework
CoreMedia.framework
opencv2.framework
……
2.修改 Build Settings
'Build Options'->'Enable Bitcode'修改為NO
'Apple LLVM 8.0 - Language - C++'->'C++ Standard Library'設(shè)置為'libc++(LLCV C++ standard library with C++ 11 support)'
'Other Warning Flags'增加條目'-Wno-documentation',以屏蔽一些注釋產(chǎn)生的 warning
3.修改項(xiàng)目.pch 文件(若沒(méi)有的話,自己生成一個(gè)),將文件內(nèi)容修改成如下所示
#import <Availability.h>
#ifdef __cplusplus
#import <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
4.將調(diào)用 OpenCV 的文件后綴修改為 .mm。
5.調(diào)用 OpenCV,代碼參考官方教程Video Processing
大功告成!