mrousavy / react-native-vision-camera

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

🐛 iOS itf barcode not working #2064

Closed lucca180 closed 8 months ago

lucca180 commented 10 months ago

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

iliapnmrv commented 10 months ago

duplicate of #2060

lucca180 commented 10 months ago

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.

klabusta commented 8 months ago

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?

mrousavy commented 8 months ago

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.

klabusta commented 8 months ago

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

mrousavy commented 8 months ago

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 :)

klabusta commented 8 months ago

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.

mrousavy commented 8 months ago

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 commented 8 months ago

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