I'm trying to detect a QRCode from an UIImage using the CIDetector in order to extract the messageString from it.
I have a function that basically receives an UIImage as input and returns the decoded messageString.
The UIImage that I pass to this function is extracted from the user Gallery using the PHAsset, PHAssetCollection, PHImageRequestOptions etc. The request is made synchronously and all the images I get are with good quality (I've tried to present the image in an UIImageView just to make sure the image is readable).
Here you can see a snippet of the code to request the images:
let _: PHImageRequestID = PHImageManager.defaultManager().requestImageForAsset(asset as! PHAsset, targetSize: size, contentMode: PHImageContentMode.AspectFit, options: options, resultHandler: { (image: UIImage?, info:[NSObject : AnyObject]?) -> Void in
images.append(image!)
})
After getting the images I want to detect the QRCodes and I'm using the following code:
func scanImage(image: CIImage) -> String {
let detector = CIDetector(ofType: CIDetectorTypeQRCode, context: nil, options: [CIDetectorAccuracy:CIDetectorAccuracyHigh])
var image = CIImage(image: uiimage)
var decode = ""
let features = detector.featuresInImage(image!)
for feature in features as! [CIQRCodeFeature] {
decode = feature.messageString
}
return decode
}
I found this (Core Image Detector(CIDetector) is not detecting QRCodes) and other similar questions but none of them seems to work.
This was tutorial I followed https://www.shinobicontrols.com/blog/ios8-day-by-day-day-13-coreimage-detectors
Am I doing something wrong?
Thanks in advance