0

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!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
James Hollyer
  • 277
  • 1
  • 3
  • 18
  • have you tried your code on an image of a qr code (e.g. https://en.wikipedia.org/wiki/File:Wikipedia_mobile_en.svg)? Are you running on iOS 8 and above (not supported otherwise? Finally, I tried to find an example where context isn't nil but I couldn't. Weird. – Roy Falk Nov 13 '15 at 06:29
  • Also, don't try this in a simulator. Apparently, it doesn't always work. (http://stackoverflow.com/a/30230136/5276890, https://forums.developer.apple.com/thread/20887) – Roy Falk Nov 13 '15 at 06:34
  • Thanks for answering! Yes, I am testing on a IPhone 6+ running IOS 8.4. I tried images that I took of a QRCode but, I just downloaded that image that you linked and still didn't get any results. – James Hollyer Nov 13 '15 at 18:02
  • So some progress was made. I took a screen shot on my phone of that Wiki QRCode and the screen shot worked. It found the QRCode and read it properly. It is still not picking up on other photos no matter how nice I try to make it...I even printed a simple QR code onto some white paper sat in good light and got only that code in the picture. Can only get that one image to work. I tried changing the accuracy to Low...didnt change anything. – James Hollyer Nov 13 '15 at 19:46
  • 1
    Also, note that probably only ISO18004 is supported (https://developer.apple.com/library/prerelease/ios/documentation/QuartzCore/Reference/CIQRCodeFeature/index.html) and there are other formats out there. – Roy Falk Nov 13 '15 at 20:11
  • Did you find a solution @JamesHollyer ? I'm facing the same situation. It's strange because it used to work a few weeks/months ago, but not anymore... – Marie Dm May 19 '16 at 15:27

1 Answers1

0

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.