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

那年仲夏 提交于 2019-11-29 02:23:59

问题


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);
}

回答1:


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());
        }
    }



回答2:


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/



来源:https://stackoverflow.com/questions/15107610/how-to-read-multiple-qr-codes-from-one-image-using-zxing-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!