Read Binary Qr Code with Avfoundation

Extracting binary data from QR-code with zbar

I am not sure what those bytes represent, probably zbar is trying to interprete the bytes as a UTF-8 string even though the QR is in byte mode.

Switching to zxing fixed everything, there is no interleaved unexpected byte and the raw data contains the entire QR code including the mode, terminator, padding etc... Also it seems to never fails, while zbar seemed to fail sometime.

AVFoundation stop after successful scan

Try this in your delegate method

func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) {

if metadataObjects == nil || metadataObjects.count == 0 {
qrCodeFrameView?.frame = CGRect.zero
return
}

let metadataObj = metadataObjects[0] as! AVMetadataMachineReadableCodeObject

if supportedBarCodes.contains(metadataObj.type) {

let barCodeObject = videoPreviewLayer?.transformedMetadataObject(for: metadataObj)
qrCodeFrameView?.frame = barCodeObject!.bounds
print(metadataObj.stringValue)

// Stop capture session
videoPreviewLayer?.isHidden = true
qrCodeFrameView?.isHidden = true
self.captureSession?.stopRunning()
}

Can not get info out of generated QRCode

QR Codes holds lots of data based on these parameters.

  • Data type
  • Size a.k.a pixels
  • Error correction level

Data type can be Numeric, Alphanumeric and Binary.
Error correction level can be categorised as Type L,M,Q and H based on loss recovery possible.

so as per your case you want to generate 30*30 alphanumeric so obviously you cant store more then allowed values. So make it bigger or reduce the data. To make a note all the QR code readers are not same.

For more info check this table



Related Topics



Leave a reply



Submit