zxing-js / library

Multi-format 1D/2D barcode image processing library, usable in JavaScript ecosystem.
https://zxing-js.github.io/library/
Apache License 2.0
2.49k stars 547 forks source link

Unable to detect and decode 6x6 Data Matrix #466

Open karimkozman opened 3 years ago

karimkozman commented 3 years ago

Describe the bug When trying to scan a 6x6 data matrix with BrowserMultiFormatReader(), it's having trouble detecting and decoding it from a phone's camera or a PC's webcam. It works fine with a 4x4 data matrix with the cam and it doesn't have a problem decoding if I just provide the 6x6 data matrix image directly and try to decode it with BrowserMultiFormatReader().decodeFromImage(img) like this example:

import { BrowserMultiFormatReader } from '@zxing/library';

const img = new Image();
img.src = '../DataMatrix.png';

const reader = new BrowserMultiFormatReader();
const result = await reader.decodeFromImage(img);
         if (result) {
             console.log("result", result.text);
          }

It can't detect the barcode using this example:

import { BrowserMultiFormatReader } from '@zxing/library';

const codeReader = new BrowserMultiFormatReader();

codeReader?.decodeFromVideoDevice(undefined, 'video', (result, err) => {
                if (result) {
                    // can't detect and decode
                    console.log(result.text);
                }
                // console still logs "NotFoundException" even when I'm seeing this issue solved here: https://github.com/zxing-js/library/pull/381
                if (err && !(err instanceof NotFoundException)) {
                    console.error(err);
                }
        });

I also tried capturing an image every 0.5 seconds with a different package and decoding it with decodeFromImage() to no avail as well

import { Plugins } from "@capacitor/core"
import { BrowserMultiFormatReader } from '@zxing/library';

   const startScan = async () => {
        const _capture = async () => {
            if (camera) {
                const camCapture = await camera.capture();
                const img = new Image();
                img.src = `data:image/jpeg;base64,${camCapture.value}`;

                const reader = new BrowserMultiFormatReader();
                const result = await reader.decodeFromImage(img);
                if (result) {
                    // can't detect and decode or just takes forever
                    console.log("result", result);

                    camera.stop();
                } else {
                    requestAnimationFrame(startScan);
                }
            }
        };

        try {
            const { CameraPreview } = Plugins;
            camera = CameraPreview;
            await camera.start({ position: 'rear', toBack: true, quality: 100 });

            setTimeout(async () => {
                try {
                    await _capture();
                } catch (err) {
                    requestAnimationFrame(startScan);
                }
            }, 500);
        } catch (err) {
            console.log(err);
        }    
}

Screenshots Here is the 6x6 data matrix code that I'm using.

Screen Shot 52
github-actions[bot] commented 6 months ago

Stale issue message