mrousavy / react-native-vision-camera

📸 A powerful, high-performance React Native Camera library.
https://react-native-vision-camera.com
MIT License
7.25k stars 1.06k forks source link

✨ Support export of rawBytes/Data in barcode scanning #2701

Open tastydev opened 5 months ago

tastydev commented 5 months ago

What feature or enhancement are you suggesting?

There are Usecases where the rawBytes of the barcode/datamatrix/qr-code have to be interpreted as they are meant to be interpreted. Not every barcode data is utf8 encoded, so it would be great to export the rawBytes and let the application which retrieves them, decode with their preferred character encoding.

I.e i need to parse/decode xml data with the character encoding latin1 but i can't do it consistently as the default barcode scan displayValue encodiing is utf8 inside MLKit and iOS which breaks the xml if i.e ä,ü,ö appear inside the bytes as they are encoded differently on utf8 (bytes per character)

See Alternatives/Workarounds for a deep dive

What Platforms whould this feature/enhancement affect?

iOS, Android

Alternatives/Workarounds

On Android it is easily possible to export the read bytes with https://developers.google.com/android/reference/com/google/mlkit/vision/barcode/common/Barcode#getRawBytes() as MlKit already stores them.

On iOS i couldn't find an easy way to retrieve the rawBytes yet. I know the bytes have to be there but i can't find the reference. Maybe someone has an Idea? If it is absolutly not possible to retrieve the rawBytes through the apple iOS sdk maybe it would be needed to switch to MlKit also for iOS and use their swift api to retrieve https://developers.google.com/ml-kit/reference/swift/mlkitbarcodescanning/api/reference/Classes/Barcode#rawdata

Additional information

mrousavy commented 5 months ago

I searched for similar feature requests in this repository and found none.

This is a duplicate of https://github.com/mrousavy/react-native-vision-camera/issues/2572.

Anyways - we can leave this open, but there is no way to get the raw binary data of a QR code on iOS using the iOS APIs for barcode reading.

I will not replace the iOS implementation with MLKit - I explained that in a lot of other issues already, the iOS implementation is a "free" extra Camera output, whereas using MLKit would require to be put into a Frame Processor.

So if I use MLKit on iOS, you'd need to enable Frame Processors, download the additional dependency, and potentially also introduce higher CPU usage, thermal usage and RAM usage.

I believe the iOS APIs are much more optimized and extremely lightweight. Also, no dependency on Google APIs.

mrousavy commented 5 months ago

If you absolutely need binary data - just use a Frame Processor Plugin, as mentioned in #2572. You can easily use MLKit's APIs from Frame Processor Plugins with just a few tiny lines of native code :)