Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
}
like image 571
She Smile GM Avatar asked Feb 27 '13 08:02

She Smile GM


People also ask

How do I scan multiple QR Codes?

Hello please check in the Zxing Barcode Scanner app it has option in Settings to Scan Bulk Barcodes so u enable it and check it u can read Multiple QR codes at a time from one or more Images and also check the Source code of Zxing library to Known the detailed Information .

Can you combine 2 QR Codes?

Yes, it is possible to create one QR Code for multiple links. You can deploy a multi URL QR Code that directs to a landing page with multiple links for users to click on.

What happens if 2 QR Codes are the same?

Even if two QR Codes store identical data, the pattern might or might not be different depending on the QR Code generator used. The primary reason for the change is due to the internal expression of the QR Code (numeric code, alphanumeric code, and so on). If this expression varies, then the data pattern also varies.


1 Answers

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());
        }
    }
like image 113
user2801456 Avatar answered Sep 19 '22 12:09

user2801456