serratus/quaggaJS

QuaggaJS Does Not Read Multiple Files

Opened this issue · 5 comments

Hello,
I'm having a small problem where I can't upload more than one local file and get Quagga to read all those files. Can anybody help me?
Thankful!

I am using Working with file-input example .

I don't see any code to handle multiple files in this situation. I suspect it might be best to construct your own sample to accept multiple files from the file reader api, if that's even a thing, and loop through them.

First off, thanks for the library, it's pretty rad.
Has anyone had success using Quagga with the html file input and multiple setting? I'm trying to do it now, but keep running into a problem where the results are the same for each photo (just n times accurate results from one of the images, where n is the number of images).

for (let i = 0; i < files.length; i++) {

      Quagga.decodeSingle({

            locator: {
              patchSize: "large",
              halfSize: true
            },

            inputStream: {
              size: 1600
            },

            decoder: {
              readers: ["code_128_reader"]
            },
            locate: true, 
            src: URL.createObjectURL(files[index])
        }, function(result){
            console.log(result);
            console.log(result.codeResult); 
        }
     );
    }

That's pretty much the code being run. I get this error too.
quaggaerror

So I did some more digging and found that processing images in parallel is still an on going issue (pull #319). For the time being, if anyone stumbles across this, I was able to process multiple images sequentially as shown below:

    function readBarcode() {
        if (imgFiles.length !== 0) { //imgFiles is an array of image urls.
          let config = {
            locator: {
              patchSize: "large",
              halfSample: true
            },
            decoder: {
              readers: [
                {
                  format: "code_128_reader",
                  config: {}
                }
              ],
            },
            inputStream: { size: 1600 },
            locate: true,
            src: imgFiles.shift()
          };
          Quagga.decodeSingle(config, result => {
            if (result) {
            console.log(result);
            console.log(result.codeResult);
            } else {
             console.log('nothing');
            }
            readBarcode();
          });
        } else {
          console.log('no more files!');
        }
    }

Yes, parallel processing using the same Quagga instance is pretty much a problem, and there's no way to make multiple instances given the current structure. I think restructuring the entire thing is a much better idea than just wrapping it all, and it's something that's been in progress for a couple of months now on this fork: https://github.com/ericblade/quagga2

Restructuring is also necessary to make multi-threading significantly more useful, and the same effort to restructure for parallel processing, will be quite useful for multi-threading as well.

My quagga2 repo does add ability to return a Promise from decodeSingle(), which does allow one to await on several decodeSingle calls, and it will perform them all in serial presently, but hopefully once it's safe to decode in parallel that will just work with no changes for the user of quagga :-) Of course, also hoping that the callback interface will be fixed as well..

If anyone's still interested in parallel processing, see ericblade/quagga2#171