Vision Framework Barcode detection for iOS 11

后端 未结 3 1373
悲哀的现实
悲哀的现实 2021-01-02 12:32

I\'ve been implementing a test of the new Vision framework which Apple introduced in WWDC2017. I am specifically looking at the barcode detection - I\'ve been able to get af

3条回答
  •  不知归路
    2021-01-02 13:27

    If you want to get the raw Data from the VNBarcodeObservation directly without it having to conform to some string encoding you can strip of the first 2 and 1/2 bytes like this, and get actual data without the QR code header.

                guard let barcode = barcodeObservation.barcodeDescriptor as? CIQRCodeDescriptor else { return }
                let errorCorrectedPayload = barcode.errorCorrectedPayload
                let payloadData = Data(bytes: zip(errorCorrectedPayload.advanced(by: 2),
                                                  errorCorrectedPayload.advanced(by: 3)).map { (byte1, byte2) in
                    return byte1 << 4 | byte2 >> 4
                })
    

提交回复
热议问题