4

I am trying to read barcode with the help if ZXing library for android. in my app when I click a button I am taken to the barcode reader activity where I read the code with the help if ZXing reader. My app can successfully read QR codes at this point but the problem is I have to hold the camera at a certain distance/angle (not fixed btw) every time. So naturally i am going through a mini workout (exaggeration) while i reading a QR code. Also, i tried turning on the flash, but when i do it becomes more difficult task to read one. I have user mobile vison library which is very fast but it does not have flash light support at this moment (or i may not have found how to turn the flash light on).

I am guessing my problem has something to do with the resolution. the barcode is printed from a machine which uses thermal printer with very low resolution. Since i cannot change the resolution of the printer, is there a way to lower the resolution at which ZXing is reading the barcode?

(PS I got the idea of lower resolution form the fact that Mobile Vision let us change the resolution and I had problems with higher resolution reading).

I would prefer to use Mobile Vision if there is a way to turn the flash light on.

my code for barcode reading class looks like this

private ZXingScannerView mScannerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mScannerView = new ZXingScannerView(this);
    mScannerView.setAutoFocus(true);
    //mScannerView.setFlash(true);
    setContentView(mScannerView);
}

@Override
protected void onResume() {
    super.onResume();
    mScannerView.setResultHandler(this);
    mScannerView.startCamera();
}

@Override
protected void onPause() {
    super.onPause();
    mScannerView.stopCamera();
}

@Override
public void handleResult(Result result) {

    if (result.getText() != null) {
        Intent qrCodeIntent = new Intent();
        qrCodeIntent.putExtra("barcode", result.getText());
        setResult(CommonStatusCodes.SUCCESS, qrCodeIntent);
        Log.v("Code", result.getText());
        Log.v("Code Format", result.getBarcodeFormat().toString());
        mScannerView.stopCamera();
        finish();
    }

}

The qr this is the QR

Mill3r
  • 544
  • 1
  • 10
  • 31

2 Answers2

3

If I remember correctly, by default, ZXing uses all formats' filters to check an image against. I mean, it firstly scans if is, for example, EAN13, than if it is UPC-A, and so on until it gets to QR-parser. It is possible to set specific decoders to the ZXing's scanning view. I am sure it will speed scanning process up.

nyarian
  • 4,085
  • 1
  • 19
  • 51
  • Thanks for the suggestion. I must say it has definitely improved the speed a lot. However, it is still very slow. and it still cannot read it at all if i turn on the flash. – Mill3r Nov 24 '18 at 09:18
  • 2
    I doubt about that it has to work correctly with flash turned on, because it defenitly corrupts a picture. Have you considered Scandit? – nyarian Nov 24 '18 at 10:17
  • is this a paid service or something like that? I am not looking for pair service at the moment. Thank you for suggestion anyways. also i guess you are trying to say "it does not corrupt the picture" and i agree to it. but somehow this is happening for my case. – Mill3r Nov 24 '18 at 11:28
2

I am getting faster experience by setting the following things. I need QR code scan. So, I set IntentIntegrator.QR_CODE.

IntentIntegrator integrator = new IntentIntegrator(activity);
                    integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
integrator.setPrompt("Scan");
integrator.setCameraId(0);
integrator.setBeepEnabled(true);
integrator.setBarcodeImageEnabled(false);
integrator.setOrientationLocked(true);
integrator.initiateScan();

I also remove camera auto focus from manifest.

N.B. I am using this library.

Shihab Uddin
  • 6,699
  • 2
  • 59
  • 74