ios - 核心图像检测器(CIDetector)未检测到 QRCodes

标签 ios swift core-image

我试图让我的应用程序的用户能够从他们的库中获取图像并扫描其中的 QRCode。相关代码如下:

这是从图像选择器返回所选图像的函数。

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 扫描:

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。我从各个方向和尺寸拍摄了图像。我无法得到任何结果。

有什么想法吗?

谢谢!

最佳答案

问题出在相册中的照片质量上。 如果您将 bundle 中的 qr 图像文件替换为“image”,例如 [UIImage imageNamed:@"foobar.png"],则会出现 qr 结果。 顺便说一句,我尝试了五张照片,但没有成功。

关于ios - 核心图像检测器(CIDetector)未检测到 QRCodes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33682784/

相关文章:

ios - 识别 UITableViewCell 中的 UIButton 不起作用 - Swift

ios - 具有常量值的映射在简单闭包中失败

ios - Objective C Table Cell ContentView view hierarchy is not prepared for the constraint

swift - 这个 Swift 语法是什么意思?

ios - 裁剪 UIImage 没有产生预期的裁剪 - swift ?

ios - 在NSString中,长度是属性还是函数?

ios - 我如何知道 AVPlayer 视频何时结束?

ios - 是否可以部分执行 ARWorldMap 重新定位而不是立即添加所有 ARAnchors?

ios - 如何从 CIImage 中将 CVPixelBuffer 读取为 4 channel 浮点格式?

ios - 使用 CIAdditionCompositing 添加纯黑色时的预期行为?