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("无法识别")

            }

  • 相关阅读:
    java内存模型
    类、对象和接口
    Python--数据存储:pickle模块的使用讲解
    Python--常用的内置函数
    Python--迭代器和生成器的定义和案例
    Python--作业2--对员工信息文件,实现增删改查操作
    Python--文本基本操作
    Python--字符串基本操作
    Python--字典基本操作
    Python--作业1--购物车程序
  • 原文地址:https://www.cnblogs.com/jinlongyu123/p/9707208.html
Copyright © 2011-2022 走看看