欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS開發(fā)教程之識別圖片中二維碼功能的實現(xiàn)

 更新時間:2018年07月13日 10:46:40   作者:cdcyd  
長按識別二維碼這個功能相信對大家來說都不陌生,最近工作中就遇到了這個需求,所以下面這篇文章主要給大家介紹了關(guān)于利用iOS識別圖片中二維碼的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下

前言

大家應(yīng)該都知道在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中可以傳的參數(shù)
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 // 設(shè)置返回矩形特征的最多個數(shù) 1 ~ 256 默認(rèn)值為1
public let CIDetectorNumberOfAngles: String // 設(shè)置角度的個數(shù) 1, 3, 5, 7, 9, 11
public let CIDetectorImageOrientation: String // 識別方向
public let CIDetectorEyeBlink: String // 眨眼特征
public let CIDetectorSmile: String // 笑臉特征
public let CIDetectorFocalLength: String // 每幀焦距
public let CIDetectorAspectRatio: String // 矩形寬高比
public let CIDetectorReturnSubFeatures: String // 文本檢測器是否應(yīng)該檢測子特征,默認(rèn)值是否

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

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.創(chuàng)建識別器,3個參數(shù)

 ofType:識別類型
 CIDetectorTypeFace 面部識別
 CIDetectorTypeText 文本識別
 CIDetectorTypeQRCode 條碼識別
 CIDetectorTypeRectangle 矩形識別

 context:上下文,默認(rèn)傳nil

 options:識別精度
 CIDetectorAccuracyLow 低精度,識別速度快
 CIDetectorAccuracyHigh 高精度,識別速度慢
 */
 let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: options)

 /**
 5.獲取識別結(jié)果,2個參數(shù)

 in:需要識別的圖片

 options:需要識別的特征
 CIDetectorMinFeatureSize: 指定最小尺寸的檢測器,小于這個尺寸的特征將不識別,CIDetectorTypeFace(0.01 ~ 0.50),CIDetectorTypeText(0.00 ~ 1.00),CIDetectorTypeRectangle(0.00 ~ 1.00)
 CIDetectorTracking: 是否開啟面部追蹤 TRUE 或 FALSE
 CIDetectorMaxFeatureCount: 設(shè)置返回矩形特征的最多個數(shù) 1 ~ 256 默認(rèn)值為1
 CIDetectorNumberOfAngles: 設(shè)置角度的個數(shù) 1, 3, 5, 7, 9, 11
 CIDetectorImageOrientation: 識別方向
 CIDetectorEyeBlink: 眨眼特征
 CIDetectorSmile: 笑臉特征
 CIDetectorFocalLength: 每幀焦距
 CIDetectorAspectRatio: 矩形寬高比
 CIDetectorReturnSubFeatures: 文本檢測器是否應(yīng)該檢測子特征,默認(rèn)值是否
 */
 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 (本地下載

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

最新評論