How to read multiple qr codes from one image using zxing library

21,721

i have created one app for camera i have used intent as the default Camera app is there with every Andriod OS and generally they are better optimized for that device than writing a generic Camera app which would be optimized for your phone only...so for camera better use intent.

For Extracting multiple QR from a Single image i tried the code below.
But results are not consistent some time I get 1 or 2 or 3 out of 4 some time none....its not perfect solution

if(photo == null) 
        return;
    Bitmap ScaledQr = null;
    ScaledQr = Bitmap.createScaledBitmap(photo, 640,480, false);
    BinaryBitmap Qr = BitMap2BinayBitmap(ScaledQr);
    Result [] kpResultMulti = null;
    Result kpResultSingle = null;
    Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
    hints.put(DecodeHintType.TRY_HARDER, true);
    //hints.put(DecodeHintType.PURE_BARCODE, true);

    try {
        kpResultMulti = kpReaderArr.decodeMultiple(Qr,hints);
    } catch (NotFoundException e) {
        // TODO Auto-generated catch block
        msbox("Exception","NotFoundException");
        e.printStackTrace();
    }

    if(kpResultMulti != null){
        msbox("Total Result" ,kpResultMulti.length +"");// + photo.getWidth() +     "Height=" + photo.getHeight());
        for(Result kp : kpResultMulti)
        {

            msbox("Results",kp.getText());
        }
    }
Share:
21,721
She Smile GM
Author by

She Smile GM

Software Engineer @ D &amp; T IT Services, Inc. Nerubia Web Solutions, Inc. back on track

Updated on July 09, 2022

Comments

  • She Smile GM
    She Smile GM almost 2 years

    I am currently developing a scanner that reads multiple QR codes found in one image. I manage to read the QR codes in the image but it's giving me inconsistent results. Assuming there are 4 QR codes in the image, sometimes I can read 2 and sometimes 3 or just 1. Unlike in the original scanner (ZXing Scanner) it decodes fast. While in my case, I have to make sure there is enough light and the image is not blurred to decode it.

    I am using the QRCodeMultiReader to decode the image. Currently using ZXing Library to create the application.

    Below is the snippet of my code:

    public void onPictureTaken(byte[] data, Camera camera) {
       BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inMutable = true;
       Bitmap bitmap = BitmapFactory
                .decodeByteArray(data, 0, data.length, opt);
       Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
       hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
       LuminanceSource source = new RGBLuminanceSource(bitmap);
    
       QRCodeMultiReader multiReader = new QRCodeMultiReader();
       Result[] results = multiReader.decodeMultiple(new BinaryBitmap(
       new HybridBinarizer(source)), hints);
    }