20

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);
}
Sean Owen
  • 66,182
  • 23
  • 141
  • 173
She Smile GM
  • 1,322
  • 1
  • 11
  • 33
  • 2
    have you find any perfect solution to read multiple barcodes ?/ – Ando Masahashi Jun 23 '14 at 08:16
  • unfortunately I haven't because we stop the development for that feature. But will continue finding solution for this especially that I'm back in android. – She Smile GM Jun 24 '14 at 00:37
  • ok can you share me code what you have tried before ? – Ando Masahashi Jun 24 '14 at 04:57
  • I just used the zxing library and set up my code for camera. I just followed the android tutorial in setting up the camera view in the main activity. I don't have the copy of the working code now since I am no longer connected with the client who asked me to do the feature. I don't keep codes since it's own by the client already. – She Smile GM Jun 25 '14 at 05:13
  • @SheSmileGM Please help me, I am looking for the same thing. But in my case only one QR code read is fine among of all because all codes are same. Please try to give me answer over here : http://stackoverflow.com/questions/30767188/scan-qr-code-if-multiple-qr-code-showing-on-screen – sam_k Jun 12 '15 at 15:15
  • You should be able to use the getResultPoints() method from the available results to find the location within the original image of the match, and use that to delete that area of the image. Then you can repeat the decoding steps until no more results are found. – Logan Pickup Jul 31 '16 at 22:44

2 Answers2

2

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());
        }
    }
Arun Bertil
  • 4,598
  • 4
  • 33
  • 59
0

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 .

https://code.google.com/p/zxing/

androidgeek
  • 3,440
  • 1
  • 15
  • 27
  • didn't notice that i can change the setting to scan multiple code in zxing scanner, thanks for that. Will debug again the zxing scanner source code. – She Smile GM Feb 27 '13 at 10:09
  • 2
    Bulk Scan has nothing to do with reading multiple barcodes at once, but reading several barcodes in succession. There is no option in the app to scan several barcodes at once, but there is in the library. – Sean Owen Feb 27 '13 at 10:16
  • @SeanOwen yes, the only option in the app is reading several barcodes in succession, but not reading at once. But in the library, the result is not consistent, any suggestion on how to get the image from camera coz in my end, i use `camera.takePicture(null,null,mPicture)` to get it. It's a bit challenging to debug the zxing library, what i notice is there's a resultpointcallbacks, I'm uncertain how it works or how to get it or what its for. – She Smile GM Feb 28 '13 at 01:32