简体   繁体   English

核心图像检测器(CIDetector)未检测到QRCode

[英]Core Image Detector(CIDetector) is not detecting QRCodes

I am trying to give the user of my app the ability to take an image from their library and scan the QRCode from it. 我正在尝试让我的应用程序用户能够从其库中获取图像并从中扫描QRCode。 Here is the relevant code: 以下是相关代码:

This is the function that returns from the Image Picker with the selected image. 这是从图像选择器返回的带有选定图像的功能。

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
    let thisImage:CIImage? = CIImage(image: image)
    let code = performQRCodeDetection(thisImage!)

    self.dismissViewControllerAnimated(true, completion: nil)

    self.performSegueWithIdentifier("goBackSegue", sender: code)


}

Inside that function I call this function to do the QRCode scanning: 在该函数内部,我调用此函数进行QRCode扫描:

func performQRCodeDetection(image: CIImage) -> String {
    var decode = ""
    let options = [CIDetectorAccuracy: CIDetectorAccuracyHigh]
    let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: options)

    let features = detector.featuresInImage(image)
    for feature in features as! [CIQRCodeFeature] {
        decode = feature.messageString
    }
    return decode
}

The variable features always comes back empty. 可变功能始终返回为空。 The image definitely has a QRCode in it. 该图像中肯定有QRCode。 I took the image from all orientations and sizes. 我从各个方向和大小拍摄了图像。 I cannot get any results. 我没有任何结果。

Any thoughts? 有什么想法吗?

Thanks! 谢谢!

the issue is on photo quality in the photo album. 问题在于相册中的照片质量。 if you put a qr image file from bundle replacing "image" eg. 如果您将捆绑包中的qr图片文件替换为“ image”,例如。 [UIImage imageNamed:@"foobar.png"], the qr result will appear. [UIImage imageNamed:@“ foobar.png”],将显示qr结果。 By the way, I tried may photos, no luck to get it works. 顺便说一句,我尝试了可能的照片,但没有运气使它起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM