国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS開發教程之識別圖片中二維碼功能的實現

2020-07-26 02:25:42
字體:
來源:轉載
供稿:網友

前言

大家應該都知道在iOS的CoreImage的Api中,有一個CIDetector的類,Detector的中文翻譯有探測器的意思,那么CIDetector是用來做哪些的呢?

它可以:

  • CIDetectorTypeFace 面部識別
  • CIDetectorTypeText 文本識別
  • CIDetectorTypeQRCode 條碼識別
  • CIDetectorTypeRectangle 矩形識別

這個類其實很簡單,它的頭文件代碼很少,下面來看一下注釋

open class CIDetector : NSObject { // 初始化方法 public init?(ofType type: String, context: CIContext?, options: [String : Any]? = nil) // 獲取識別特征 open func features(in image: CIImage) -> [CIFeature] open func features(in image: CIImage, options: [String : Any]? = nil) -> [CIFeature]}// 識別類型public let CIDetectorTypeFace: String // 面部識別public let CIDetectorTypeRectangle: String // 矩形識別public let CIDetectorTypeQRCode: String // 條碼識別public let CIDetectorTypeText: String // 文本識別// 下面定義的就是options中可以傳的參數public let CIDetectorAccuracy: String // 識別精度public let CIDetectorAccuracyLow: String // 低精度,識別速度快public let CIDetectorAccuracyHigh: String // 高精度,識別速度慢public let CIDetectorTracking: String // 是否開啟面部追蹤public let CIDetectorMinFeatureSize: String // 指定最小尺寸的檢測器,小于這個尺寸的特征將不識別,CIDetectorTypeFace(0.01 ~ 0.50),CIDetectorTypeText(0.00 ~ 1.00),CIDetectorTypeRectangle(0.00 ~ 1.00)public let CIDetectorMaxFeatureCount: String // 設置返回矩形特征的最多個數 1 ~ 256 默認值為1public let CIDetectorNumberOfAngles: String // 設置角度的個數 1, 3, 5, 7, 9, 11public let CIDetectorImageOrientation: String // 識別方向public let CIDetectorEyeBlink: String // 眨眼特征public let CIDetectorSmile: String // 笑臉特征public let CIDetectorFocalLength: String // 每幀焦距public let CIDetectorAspectRatio: String // 矩形寬高比public let CIDetectorReturnSubFeatures: String // 文本檢測器是否應該檢測子特征,默認值是否

下面是二維碼識別的實例代碼

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { // 1.取到圖片 let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage // 2.生成CIImage let ciimage = CIImage(cgImage: image!.cgImage!) // 3.識別精度 let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh] /** 4.創建識別器,3個參數 ofType:識別類型 CIDetectorTypeFace 面部識別 CIDetectorTypeText 文本識別 CIDetectorTypeQRCode 條碼識別 CIDetectorTypeRectangle 矩形識別 context:上下文,默認傳nil options:識別精度 CIDetectorAccuracyLow 低精度,識別速度快 CIDetectorAccuracyHigh 高精度,識別速度慢 */ let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: options) /** 5.獲取識別結果,2個參數 in:需要識別的圖片 options:需要識別的特征 CIDetectorMinFeatureSize: 指定最小尺寸的檢測器,小于這個尺寸的特征將不識別,CIDetectorTypeFace(0.01 ~ 0.50),CIDetectorTypeText(0.00 ~ 1.00),CIDetectorTypeRectangle(0.00 ~ 1.00) CIDetectorTracking: 是否開啟面部追蹤 TRUE 或 FALSE CIDetectorMaxFeatureCount: 設置返回矩形特征的最多個數 1 ~ 256 默認值為1 CIDetectorNumberOfAngles: 設置角度的個數 1, 3, 5, 7, 9, 11 CIDetectorImageOrientation: 識別方向 CIDetectorEyeBlink: 眨眼特征 CIDetectorSmile: 笑臉特征 CIDetectorFocalLength: 每幀焦距 CIDetectorAspectRatio: 矩形寬高比 CIDetectorReturnSubFeatures: 文本檢測器是否應該檢測子特征,默認值是否 */ let features = detector?.features(in: ciimage, options: nil) // 遍歷出二維碼 for item in features! where item.isKind(of: CIQRCodeFeature.self) { print((item as! CIQRCodeFeature).messageString ?? "") } }

Demo地址 https://github.com/cdcyd/CCQRCode (本地下載)

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對武林網的支持。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 萨迦县| 资溪县| 九龙坡区| 元朗区| 自治县| 凤凰县| 连城县| 吴旗县| 岳池县| 牡丹江市| 武义县| 镇原县| 龙口市| 军事| 那曲县| 东安县| 黄平县| 西乡县| 岑巩县| 法库县| 阜阳市| 桐城市| 根河市| 保定市| 常德市| 南昌市| 临夏市| 杭州市| 修文县| 庆阳市| 平度市| 于田县| 寻乌县| 孝昌县| 楚雄市| 日喀则市| 永川市| 军事| 泗洪县| 仪陇县| 延吉市|