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

            }

  • 相关阅读:
    python入门(3)净化雷锋网网页内容
    Ecos3.0 Spi Driver for Leon3
    梦断代码1了解你的编译器和IDE
    诚聘高级测试工程师(北京职位)
    高级PHP开发工程师、高级前端开发工程师(北京职位)
    MySQL DBA (北京职位)
    赴百度 Web前端工程师 三个职位
    new与malloc的区别
    Google C++编程风格指南
    MFC的picture控件 静态加载与动态加载
  • 原文地址:https://www.cnblogs.com/jinlongyu123/p/9707208.html
Copyright © 2020-2023  润新知