核心图像检测器(CIDetector)未检测到QRCode [英] Core Image Detector(CIDetector) is not detecting QRCodes
问题描述
我正在尝试让我的应用程序用户能够从其库中获取图像并从中扫描QRCode。以下是相关代码:
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)
}
内部该函数我调用此函数进行QRCode扫描:
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
}
变量功能始终返回为空。该图像中肯定有QRCode。我从各个方向和大小拍摄了图像。我没有任何结果。
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.
有什么想法吗?
谢谢!
推荐答案
问题出在相册的照片质量上。
如果您将捆绑包中的qr图像文件替换为 image,例如[UIImage imageNamed:@ foobar.png],则会显示qr结果。
顺便说一句,我尝试了可能的照片,但没有运气使它起作用。
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.
这篇关于核心图像检测器(CIDetector)未检测到QRCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!