Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💭 Getting incorrect coordinates and bounds when using CodeScanner when scanning barcodes #3011

Open
4 tasks done
shehanGuruge opened this issue Jun 19, 2024 · 2 comments
Open
4 tasks done
Labels
💭 question Further information is requested

Comments

@shehanGuruge
Copy link

shehanGuruge commented Jun 19, 2024

Question

I am using react-native-vision-camera v4.1.0, and I implemented the CodeScanner as per the docs. However every time I scan a barcode I am getting incorrect width which is in range of 3 - 10 in IOS. Hence it's impossible to map those values to the screen width and height and limit the scan area

What I tried

This is what I have done so far,

My Code Scanner looks like this

const codeScanner: CodeScanner = {
    codeTypes: ['ean-13'],
    onCodeScanned: (codes, frame) => {
      setScanFrame(frame);
      setCodeScannerHighlights(
        codes.map((code) => ({
          height: code.frame?.width ?? 0,
          width: code.frame?.height ?? 0,
          x: code.frame?.y ?? 0,
          y: code.frame?.x ?? 0,
        }))
      );
    },
  };
  

This is how I have set the codeScanner

   const device = useCameraDevice('back');
   <Camera
        style={StyleSheet.absoluteFill}
        device={device}
        isActive={true}
        codeScanner={codeScanner}
        onLayout={onLayout}
      />

I am also using onLayout to map the coordinates to the width and height of the camera view and limit the scan area like below

  const onLayout = (evt: LayoutChangeEvent) => {
    if (evt.nativeEvent.layout) {
      setLayout(evt.nativeEvent.layout);
    }
  };
  

This is the response I get

Scanned [{"value":"1234567890128","corners":[{"x":929.5000279190813,"y":801.097824131347},{"x":932.5000393631731,"y":801.0978240575837},{"y":397.90094443226377,"x":932.5000080310912},{"x":929.4999965869994,"y":397.90094450602703}],"frame":{"width":3.000011444091797,"x":929.5000076293945,"height":403.1969118118286,"y":397.9009437561035},"type":"ean-13"}] codes!

As you can see the frame width is always within 3 and 10 irrespective of how closer or away the phone/camera is from the code. Any way I could fix this? Any suggestions how I could limit the scan area using this library?

VisionCamera Version

4.0.1

Additional information

@shehanGuruge shehanGuruge added the 💭 question Further information is requested label Jun 19, 2024
@maintenance-hans maintenance-hans bot changed the title 💭Getting incorrect coordinates and bounds when using CodeScanner when scanning barcodes Jun 19, 2024
Copy link

maintenance-hans bot commented Jun 19, 2024

Guten Tag, Hans here.

Note

New features, bugfixes, updates and other improvements are all handled mostly by @mrousavy in his free time.
To support @mrousavy, please consider 💖 sponsoring him on GitHub 💖.
Sponsored issues will be prioritized.

@JshGrn
Copy link

JshGrn commented Jul 5, 2024

Any luck with this? I am getting unexpected results from the bounds, getting negative values... Do you know what order the corners are by any chance? The docs are very unhelpful on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💭 question Further information is requested
2 participants