2017-06-07 8 views
4

I GoogleMobileVision/Barcode-Detektor in meinem Swift 3.1 Projekt mit dem folgenden Code bin mit:Initiieren GMVDetector nicht

GMVDetector(ofType: GMVDetectorTypeBarcode, options: nil) 

aber in der es log zeigt:

log

Es scheint, dass GoogleMobileVision in iOS ist eine geschlossene Quelle, so dass ich nicht wirklich sehen kann, was auf der Implementationsseite passiert

Irgendwelche Gedanken, was möglich ist Läuft hier gerade?

Antwort

1

Ich denke, Sie müssen einige optionale Wert von Barcode-Typ wie EAN13 oder QRcode anstelle von Null.

var detector = GMVDetector() 
let options:[AnyHashable: Any] = [GMVDetectorBarcodeFormats : GMVDetectorBarcodeFormat.EAN13.rawValue] 
self.detector = GMVDetector.init(ofType: GMVDetectorTypeBarcode, options: options) 
0

Edited - Gelöst

Das Problem dieses Stück Code war (wie @Developer sagte)

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

ich das gleiche Problem ohne Erfolg haben, ich weiß nicht, Was ist los.

Es sieht so aus, als müsste alles so einfach sein, aber ich denke, ich habe jede Möglichkeit versucht, dies zu instanziieren. Ich suchte nach schnellen Beispielen, aber ich fand nichts Nützliches.

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)") 
      } 
     } 
    } 
} 
Verwandte Themen