NativeScript / mlkit

Apache License 2.0
24 stars 9 forks source link

BarcodeResult type mismatch between Android and iOS #48

Open boutier opened 1 year ago

boutier commented 1 year ago

Hi !

With mlkit 2.0.0, on Android, when scanning a *code, I have something like:

{
  "bounds": {
    "origin": { "x": 100, "y": 215 },
    "size": { "height": 166, "width": 172 }
  },
  "points": [
    { "x": 110, "y": 215 },
    { "x": 272, "y": 220 },
    { "x": 262, "y": 381 },
    { "x": 100, "y": 376 }
  ],
  "rawBytes": [68, 77, 83, 90, 49, 47, 49, 47, 49, 47, 49],
  "format": "QR_CODE",
  "displayValue": "DMSZ1/1/1/1",
  "rawValue": "DMSZ1/1/1/1",
  "valueType": "Text"
}

While I have on iOS:

{
  "bounds": { "y": 279, "x": 661, "width": 576, "height": 589 },
  "points": [
    { "x": 661, "y": 357 },
    { "x": 1161, "y": 279 },
    { "x": 1237, "y": 781 },
    { "x": 738, "y": 868 }
  ],
  "rawBytes": "RE1TWjEvMS8xLzE=",
  "format": ["qr_code"],
  "displayValue": "DMSZ1/1/1/1",
  "rawValue": "DMSZ1/1/1/1",
  "valueType": "text"
}

(both reordered for better readability)

The BarcodeResult interface is defined in https://github.com/NativeScript/mlkit/blob/0712e3dfe4b4d2eb4d0caa3e22786c603366f19f/packages/mlkit-barcode-scanning/index.ts

Given BarcodeResult is the reference:

Side questions about BarcodeResult:

triniwiz commented 1 year ago

For starters the android implementation was created before iOS so I failed to match the behaviour so the differences could be me trying to make things easier.

  1. Qr* This would be a serializer issue
  2. Bound* my fault here the bounds output on android is what iOS outputs but I joined them so I'll merge it.
  3. rawBytes* seems iOS and Android encoders behave a bit different, both values are rawBytes on their respective platforms byte[] and Data. If needed we can use a custom JSON parse to ensure rawBytes is returned as an Array/ArrayBuffer