react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

🐛 iOS itf barcode not working

Open lucca180 opened this issue 2 years ago • 3 comments

What's happening?

iOS barcode scanner is not working with 2 of 5 Interleaved (itf) format.

Android works fine.

image

Reproduceable Code

const device = useCameraDevice('back');

  const codeScanner = useCodeScanner({
    codeTypes: ['code-128', 'itf'],
    onCodeScanned: codes => {
      console.log(`Scanned ${codes.length} codes!`);
    },
  });

Relevant log output

N/A

Camera Device

{
  "minZoom": 1,
  "sensorOrientation": "landscape-right",
  "maxZoom": 16,
  "supportsLowLightBoost": false,
  "isMultiCam": false,
  "name": "Back Camera",
  "hasFlash": true,
  "supportsRawCapture": false,
  "supportsFocus": true,
  "neutralZoom": 1,
  "physicalDevices": [
    "wide-angle-camera"
  ],
  "hardwareLevel": "full",
  "position": "back",
  "id": "com.apple.avfoundation.avcapturedevice.built-in_video:0",
  "hasTorch": true
}

Device

iPhone 8

VisionCamera Version

3.5.1

Can you reproduce this issue in the VisionCamera Example app?

I didn't try (⚠️ your issue might get ignored & closed if you don't try this)

Additional information

lucca180 avatar Oct 23 '23 14:10 lucca180

duplicate of #2060

iliapnmrv avatar Oct 23 '23 17:10 iliapnmrv

So, on Android, ift reads both interleaved2of5 and itf14 formats. On iOS, per docs, these are two diff variables, that's why setting ift doesn't work for interleaved2of5 format.

lucca180 avatar Oct 27 '23 14:10 lucca180

I've had the same problem with some of the ITF labels I'm using. I've replaced (i.e. patched) the itf14 with interleaved2of5 in AVMetadataObject.ObjectType+descriptor.swift and they worked. Although that seems like a bad patch, as itf14 wouldn't work anymore.

Any better solution for this?

klabusta avatar Dec 21 '23 15:12 klabusta

Hey - I'm using Apple's custom QR code scanner. If it cannot scan that, there's nothing I can do. You can instead write a custom frame processor plugin (or use a community plugin) that uses a different QR model, maybe MLKit or ZXing. Dynamsoft has one as well (cc @xulihang)

Btw; can you try rotating the Camera to see if that changes anything? Maybe the orientation on the scanner is wrong (e.g. landscape left by default), then it is in fact my fault.

mrousavy avatar Jan 15 '24 13:01 mrousavy

It can scan both: itf14 and interleaved2of5. But you only map itf14 to "ITF" not both.

klabusta avatar Jan 15 '24 13:01 klabusta

Ah I see now. So instead of patching, why didn't you create a PR to fix this for everyone?

This could be a separate branch in that file to make it work :)

mrousavy avatar Jan 15 '24 13:01 mrousavy

My patch isn't fixing it. It's just using interleaved2of5 instead of itf14. But I suppose mapping both to "ITF" is a bigger change. I wouldn't know how.

klabusta avatar Jan 15 '24 13:01 klabusta

My idea was to add "interleaved2of5" as an additional branch, not to use both under the itf alias.

The downside of that is that the interleaved2of5 type is not supported on Android/MLKit afaik, so it wouldnt be cross platform

mrousavy avatar Jan 15 '24 14:01 mrousavy

https://stackoverflow.com/questions/51135855/ml-kit-barcode-detector-not-recognizing-itf-barcodes-with-4-or-less-digits <-- from 2018

mrousavy avatar Jan 15 '24 14:01 mrousavy