zoukankan      html  css  js  c++  java
  • CIDetector 相册识别二维码出错

    在做点击相册识别二维码识别不了,折腾了大半天,终于从坑里爬出来 ,下面分享一下填坑过程

    在创建相册和获取图片的时候添加上面的代码。然后用取出来的图片作为参数进行二维码识别,下面封装了一个类方法:

     public func recognizeQRCode() -> String?

        {

            let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy : CIDetectorAccuracyHigh])

            guard let imageData = UIImageJPEGRepresentation(self, 1) else {

                return nil

            }

            guard let features = detector?.features(in: CoreImage.CIImage.init(data: imageData)!) else {

                return nil

            }

            guard features.count > 0 else { return nil }

            let feature = features.first as? CIQRCodeFeature

            return feature?.messageString

        }

    具体调用如下所示:

     let image = info[UIImagePickerControllerEditedImage] as! UIImage

            guard let recognizeResult = image.recognizeQRCode() else {

                ToastUtil.showHud("无法识别")

                return

            }

            if recognizeResult.count > 0 {

              

             print("识别结果--(recognizeResult)")

            } else {

              ToastUtil.showHud("无法识别")

            }

  • 相关阅读:
    codeforces 707D-(DFS+bitset)
    codeforces Educational Codeforces Round 16-E(DP)
    codeforces 597C (树状数组+DP)
    codeforces #round363 div2.C-Vacations (DP)
    Codeforces Round #365 (Div. 2)-D Mishka and Interesting sum(树状数组)
    codeforces round367 div2.C (DP)
    June Challenge 2018 Division 2
    Codeforces Round #487 (Div. 2)
    Educational Codeforces Round 45 (Rated for Div. 2)
    [Offer收割]编程练习赛63
  • 原文地址:https://www.cnblogs.com/jinlongyu123/p/9707208.html
Copyright © 2011-2022 走看看