jdnessity
jdnessity

Reputation: 115

Initiating GMVDetector fails

I'm using GoogleMobileVision/Barcode detector in my Swift 3.1 project using the following code:

GMVDetector(ofType: GMVDetectorTypeBarcode, options: nil)

but in the log it shows:

log

It seems that GoogleMobileVision in iOS is closed source so I cannot really see what's happening on the implementation side

Any thoughts on what possibly is happening here?

Upvotes: 5

Views: 852

Answers (2)

jpl850
jpl850

Reputation: 374

Edited - Solved

The problem was this piece of code (as @Developer said)

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

I have the same problem with no success, I don't know what's going on.

It looks that it has to be anything so simple but I think I tried every way to instantiate this. I searched for swift examples but I dind't find anything useful.

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

Upvotes: 1

Mahamudul Hasan
Mahamudul Hasan

Reputation: 494

I think you need to put some optional value of barcode type like EAN13 or QRcode instead of nil.

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

Upvotes: 2

Related Questions