標(biāo)簽:iOS
OpenCV
最近嘗試在 iOS 上使用 OpenCV姻氨,網(wǎng)上的資料比較少剪验,且大多資料和源碼都已經(jīng)無用,來回折騰了好久才跑通一個基本的 Demo 程序功戚,記錄下來留作筆記。
iOS 中導(dǎo)入 OpenCV
最早嘗試 OpenCV 官網(wǎng)上的介紹的下載源碼編譯生成 framework届宠、或者直接從官網(wǎng)上下載 framework 導(dǎo)入工程乘粒,都無法使用。同樣網(wǎng)上介紹直接使用 CocoaPods 飛速導(dǎo)入 OpenCV 也無法使用轧铁。
最終在 github 上查找開源的 iOS OpenCV 源碼竟稳,找到一個可以運(yùn)行使用的項目 EasyPR-iOS,導(dǎo)入了其中的opencv2.framework
聂宾,才成功過編譯通過诊笤。
項目環(huán)境配置
開發(fā)環(huán)境:XCode8.2
1.項目中導(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.修改項目.pch 文件(若沒有的話鄙煤,自己生成一個)茶袒,將文件內(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
大功告成向叉!