Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 637
jdnessity Avatar asked Oct 18 '22 11:10

jdnessity


2 Answers

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) 
like image 185
Developer Avatar answered Oct 21 '22 03:10

Developer


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)")
            }
        }
    }
}
like image 34
jpl850 Avatar answered Oct 21 '22 02:10

jpl850