Core Image Detector(CIDetector) is not detecting QRCodes

你说的曾经没有我的故事 提交于 2019-12-12 05:26:46

问题


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. 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:

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. I took the image from all orientations and sizes. I cannot get any results.

Any thoughts?

Thanks!


回答1:


the issue is on photo quality in the photo album. if you put a qr image file from bundle replacing "image" e.g.. [UIImage imageNamed:@"foobar.png"], the qr result will appear. By the way, I tried may photos, no luck to get it works.



来源:https://stackoverflow.com/questions/33682784/core-image-detectorcidetector-is-not-detecting-qrcodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!