ericblade / quagga2

An advanced barcode-scanner written in Javascript and TypeScript - Continuation from https://github.com/serratus/quaggajs
MIT License
761 stars 85 forks source link

investigate potential problem with firefox browsers breaking in asm.js code #206

Closed ericblade closed 2 years ago

ericblade commented 4 years ago

related comments from grocy user, with sample barcode https://github.com/grocy/grocy/issues/749#issuecomment-633267729

With testing configured in cypress, we should be able to automate testing in firefox as well, will require some additional setup/configuration...

ericblade commented 4 years ago

There may be issues in Chrome as well -- i've occasionally noticed a asm.js error in chrome recently.

Borvik commented 3 years ago

Not just browsers - I'm occasionally seeing an asm error in NodeJS (running node v12.13.1):

V8: /home/dev_user/Projects/proj_name/common/temp/node_modules/.registry.npmjs.org/@ericblade/quagga2/1.2.6/node_modules/@ericblade/quagga2/lib/quagga.js:4406 Invalid asm.js: Unexpected token
ericblade commented 3 years ago

I'm not incredibly worried about this, as it doesn't seem to affect the actual results. If V8 and node are supporting asm.js now, then it'd be a lot easier to diagnose.

@Borvik could you maybe attach here a sample image that reproduces? I'll add it to the test suite, and either maybe someday I'll figure out ASM.js or we'll have someone run across this that already knows it and can fix it :-D

Borvik commented 3 years ago

Understood - yea, figured more info the better.

I think you are correct, it may not be too much of an issue for me, despite the error I am still seeing the barcodes come through.

As for which image is triggering it? Not sure - we have a batch process that scans a lot of images, most of which don't have barcodes and use the barcodes to figure out where to put the images. If I can narrow it down to 1 or 2 images, I'll try to post them.

ericblade commented 3 years ago

That would be great. I pretty much only use browser mode with LiveStream, so i'm not usually seeing this kind of stuff.

Borvik commented 3 years ago

Ok, so I think it is this image. This is the raw image I used before pre-processing and sending to quagga. We actually the pre-processing and try to decode with multiple settings to get the best results.

We user sharp and smartcrop-sharp in pre-processing

  1. Use sharp to do a composite with blend: 'colour-dodge' - helps try to make the barcodes to stand out more
  2. Use smartcrop to crop to try and find the main subject of the photo - namely the barcode
  3. Run through a number of quagga setting to try and get a result

Our base quagga call is:

Quagga.decodeSingle({
      inputStream: {
        mime,
        size: check.size // varied as part of a loop
      } as any,
      locator: {
        patchSize: check.patch, // varied as part of a loop
        halfSample: false
      },
      numOfWorkers: 0,
      decoder: {
        readers: formats
      },
      locate: true,
      src: file as any, // is actually a Buffer
      debug: false
    }, (result: any) => {
      // have result
    });
  });

Our attempts use the follow setting in the above call:

const CHECKS = [
  { size: 320, patch: 'x-large' },
  { size: 320, patch: 'large' },
  { size: 320, patch: 'medium' },
  { size: 400, patch: 'large' },
  { size: 800, patch: 'x-large' },
  { size: 800, patch: 'large' },
];

IMG_2356

ericblade commented 3 years ago

oh wow, you've done a lot of stuff! so.. one question, @Borvik what format is this barcode? :-)

Borvik commented 3 years ago

Code 39

ericblade commented 3 years ago

^^ above barcode doesn't decode in the Node tests using the default settings, so i'm adding it as another example of #191 where there are slightly different results between browser and node -- same settings work in browser test, apparently.

First EAN test in node, however, DOES present this issue with asm.js:

image

ericblade commented 3 years ago

I just did a brief investigation, and i've found two things -- it's not occuring because of minifying (as we don't minify the node library), although the packing process may otherwise be making it invalid. since the error doesn't occur on every run, it leads me to believe that something dynamic is failing, but i don't know what yet.

The other thing, is that according to a quick google, there's no hits for anyone else running into this message and wondering about it, or solving it, the only thing I got a link to was the V8 code that spits the error: https://github.com/v8/v8/blob/518ee01d390e26ca757e310b47c5f199b0552940/src/asmjs/asm-parser.cc#L435

ericblade commented 3 years ago

... i'm sure someone with some experience in asm could figure this out, but i'm not likely to be the person picking that up -- WASM effectively replaces ASM.JS and ASM.JS is deprecated, so ... as long as it's not breaking anything (which it doesn't seem to do, as browser throws the warning but decodes the file just fine), i'm not touching it unless it's to replace it with something better/modern.

I will happily accept a pull request to repair this section if someone else figures it out, but my time spent maintaining this app is better spent elsewhere right now.

ericblade commented 2 years ago

good news re: Asm.js error, sort of: asm.js error is basically a warning. It just runs the code as javascript since it can't interpret it properly into what it's looking for. bad news, although i can fix the one in this code, after i fix up several of them, i end up with one that the original author wrote which is also invalid, and i don't have any idea how to fix it, and information about asm.js is pretty sparse these days.

ericblade commented 2 years ago

closing this in favor of porting/rewriting skeletonizer to wasm