5

我使用以下代码在我的 Swift 3.1 项目中使用 GoogleMobileVision/条形码检测器:

GMVDetector(ofType: GMVDetectorTypeBarcode, options: nil)

但在日志中显示:

日志

iOS 中的 GoogleMobileVision 似乎是封闭源代码,所以我无法真正看到实现方面发生了什么

对这里可能发生的事情有任何想法吗?

4

2 回答 2

2

我认为您需要输入一些条码类型的可选值,例如 EAN13 或 QRcode,而不是 nil。

var detector = GMVDetector()
let options:[AnyHashable: Any] = [GMVDetectorBarcodeFormats : GMVDetectorBarcodeFormat.EAN13.rawValue]
self.detector = GMVDetector.init(ofType: GMVDetectorTypeBarcode, options: options) 
于 2017-08-13T10:49:13.137 回答
1

已编辑 - 已解决

问题是这段代码(正如@Developer所说)

let detectorOptions = [
        GMVDetectorBarcodeFormats : GMVDetectorBarcodeFormat.qrCode.rawValue
    ]

我有同样的问题,没有成功,我不知道发生了什么。

看起来它必须如此简单,但我想我尝试了各种方法来实例化它。我搜索了快速示例,但没有找到任何有用的东西。

var barcodeDetector : GMVDetector?

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    let detectorOptions = [
        GMVDetectorBarcodeFormats : [
            GMVDetectorBarcodeFormat.qrCode.rawValue
        ]
    ]
    self.barcodeDetector = GMVDetector(ofType: GMVDetectorTypeBarcode, options: detectorOptions)

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
}

override func viewDidAppear(_ animated: Bool) {
    if let image = UIImage(named: "QRTest.png") {
        if let barcodes = self.barcodeDetector!.features(in: image, options: nil) {
            for barcode in barcodes {
                print("\(barcode.description)")
            }
        }
    }
}
于 2017-12-11T11:00:32.250 回答