ZXing QR reader library for Android reading painfully slow - android

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

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.

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.

Related

Use google mobile vision api to freeze the screen as soon as a barcode is detected

The following method is in BarcodeCaptureActivity.java of the sample code google shared on GitHub.
#Override
public void onBarcodeDetected(Barcode barcode) {
// I want to stop preview as well as freeze the screen
// when the first barcode is detected
// What do I add here?
}

Adding Android Voice Recognition to an existing App

I have a working application that I would like to add voice commands. The current application transmits data back and forth over bluetooth on a periodic (timer) basis. The user can press Buttons and NumberPickers to modify the data being sent over bluetooth. There is also data received from the bluetooth link, and displayed in textViews. This application is currently working correctly.
What I would like to do is add voice command capability, so that the user has either the choice of pressing the Buttons/NumberPickers, or can change the values with only voice commands.
I have tested some of the Speech-to-Text examples that can be found on various websites. I have succesfully tested an App that uses RecognizerIntent. Upon a button press, a dialog pops up and you can speak words or phrases, and it correctly displays the result on the screen.
So, I think that I am close, but I'm not really sure how I can combine the Speech-to-Text with my current Bluetooth App. I don't want the user to have to press a button, I just want the App to be constantly listening. Also, I don't want the pop-up Voice Dialog on the screen.
My hardware is a Samsung tablet running Android 4.1.
I am relatively new to Android programming, so any advice (no matter how basic) is appreciated. Thanks.
To prevent the pop-up Voice Dialog on the screen, you can use the ACTION_RECOGNIZE_SPEECH intent:
private static int SR_CODE = 123;
/**
* Initializes the speech recognizer and starts listening to the user input
*/
private void listen() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
//Specify language
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.ENGLISH)
// Specify language model
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
// Specify how many results to receive
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
// Start listening
startActivityForResult(intent, SR_CODE);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == SR_CODE && resultCode == RESULT_OK) {
if(data!=null) {
//Retrieves the best list SR result
ArrayList<String> nBestList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
String bestResult = nBestList.get(0);
Toast.makeText(getApplicationContext(), bestResult, Toast.LENGTH_LONG).show;
}else {
//Reports error in recognition error in log
Log.e(LOGTAG, "Recognition was not successful");
}
}
Concerning the other issue, " I don't want the user to have to press a button, I just want the App to be constantly listening":
I'll recommend using CMUSphinx to recognize speech continuously. To achieve continuous speech recognition using google speech recognition api, you might have to resort to a loop in a background service which will take too much resources and drains the device battery.
On the other hand, Pocketsphinx works really great. It's fast enough to spot a key phrase and recognize voice commands behind the lock screen without users touching their device. And it does all this offline.
You can try the demo.
If you really want to use google's api as I've demonstrated above, see this

How correctly manage the First ZXING Intent? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have implemented the ZXing functionnality in my App to read QR-Code.
Xzing runs with Barcode scanner via an exmplicit intent so the first you initiate the intent, it will ask to install barcode.
So it redirect you to the Play Store and the application gets installed.
Anyway, there is something not really easy to manage here as the Intent has been launched but we never get a return.
So the application waits for ever....
Is there any event to intercept or something like that...
Maybe there an OnActivity result for barcode installation already in the Integrator?
I tried to first deal with the PackageManager according to what is said here Zxing via intent
But in fact the test list.size() is successfull for ... Zalando Arghhh!!!
What happens?
The goal was to check if BarCode is installed, if no, ask for install it with a StartActivityForResult and once the install is complete, launch the Scan Intent.
Regards,
So,
It's a pity I don't have an answer to my question because I wonder in fact if it's no more common than only using Xzing.
The actual prefered Xzing implementation seems to be to use an intent to launch the barCode Scanner application.
The problem occurs if BarCode Scanner is not yet installed on your device.
In that case, the intent launch the play store to let you download it.
Here is the problem because, unless I didn't understand something and as I didn't get an answer, I think I'm not wrong, once BarCode Scanner is downloaded, installed and launched, you don't receive any answer to your sent Intent! Letting your user the ass between two chairs.
Another alternative could be to deal first with the package manager to ask it if Barcode Scanner is installed. That way, you discuss with the package manager to install the app and then launch your scan intent.
Unfortunately, I also tried that but for a reason I didn't understand asking to the package manager if "com.google.zxing.client.android.SCAN" is present gives a positive answer for ... Zalando !?! Arghhh!
Other possibility should be to integrate pieces of Xzing directly in your app.
I read many posts on this subject, all based on a different Xzing version and giving different methods and I didn't succed to get a working solution.
And obviously again, it seems that sean Owen clearly discourage this solution. What I really don't understand because in some situation, having to download a third party application while you are using your app could be vey uncomfortable and doesn't improve user experience. Well that's my point of view. I assume it even if it caused a serious downgrade in Stackoverflow !!
That's said my answer is to used Zbar. Zbar is no longer maintained on Android because its developper switched to Xzing!! well....
Anyway, it's an extremely efficient and eazy to use library and especially for the last reason, it's a high quality product.
Here I explain how to implement it:
-First download the archive https://sourceforge.net/projects/zbar/files/AndroidSDK/ZBarAndroidSDK-0.1.zip
-Then extract it of course.
You will get various directories:
*examples, with a CameraTest activity I encourage you to integrate in Eclipse to test it and also because your will get its components
*libs wher you will find the subdirs x86, armeab-v7a, armeabi and zbar.jar library.
Once you have imported cameraTest project in Eclipse, you should have a fully working code scanner named CameraTestActivity.
So to integrate the functionnality in your application follow these steps:
All required components are in CameraTestActivirty of course.
Copy/paste CameraTestActivity.java and CameraPreview.java from CameraTestActivity src to your proper src directory.
You would prefer to Copy/Paste the package, as you prefer.
Personnally, I renamed CameraTestActivity to QRCodeScanActivity
Copy/Paste all directoris in libs from CameraTestActivity to you proper libs directory.
Include the following part of AndroidManifest.xml in your proper AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" /> Here it's as you want, it should work also on non autofocus devices
... your already present declarations....
....
Copy/Paste the main.xml from layout i CameraTestActivity to your proper layout directory. CameraTestActivity will force portrait orientation during the scan.
Rename this file as you want; qrcodescan.xml if you want.
You have to declare that you use zbar.jar library.
Right-click on yout application name, select properties, click on Java Build Path, then click on Add JARs and go through yourAppName\libs to select zbar.jar.
You have to change 2 or 3 little things in the code.
In QRCodeScanActivity, previously CameraTest Activity:
public class QRCodeScanActivity extends Activity {
// declare a constant to use in the Intent created in your application to start he scan.
public final static int ACTIVITY_SCAN_CODE = 33;
.....
// Declare an intent to respond to your activity
Intent activityResult = new Intent();
// Not mandatory, you can add an intermediate String to return to your application
String textScanned;
......
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Put here the name you choosed in place of main.xml
setContentView(R.layout.qrcodescan);
....
// Later you will choose if you let the TextView and the Button or not. Personnaly, I removed it to just keep the test if (barcodescanned) and its content.
scanText = (TextView)findViewById(R.id.scanText);
scanButton = (Button)findViewById(R.id.ScanButton);
scanButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (barcodeScanned) {
barcodeScanned = false;
scanText.setText("Scanning...");
mCamera.setPreviewCallback(previewCb);
mCamera.startPreview();
previewing = true;
mCamera.autoFocus(autoFocusCB);
}
}
});
}
public void onPause() {
super.onPause();
releaseCamera();
}
...............
PreviewCallback previewCb = new PreviewCallback() {
public void onPreviewFrame(byte[] data, Camera camera) {
Camera.Parameters parameters = camera.getParameters();
Size size = parameters.getPreviewSize();
Image barcode = new Image(size.width, size.height, "Y800");
barcode.setData(data);
int result = scanner.scanImage(barcode);
if (result != 0) {
previewing = false;
mCamera.setPreviewCallback(null);
mCamera.stopPreview();
SymbolSet syms = scanner.getResults();
for (Symbol sym : syms) {
scanText.setText("barcode result " + sym.getData());
barcodeScanned = true;
// Here is what you have to add to return the result to your application
textScanned = sym.getData();
activityResult.putExtra("SCANNED", textScanned);
setResult(RESULT_OK, activityResult);
finish();
}
}
}
};
// Mimic continuous auto-focusing
AutoFocusCallback autoFocusCB = new AutoFocusCallback() {
public void onAutoFocus(boolean success, Camera camera) {
autoFocusHandler.postDelayed(doAutoFocus, 1000);
}
};
}
In your application now:
Somewhere where you want to start the scan from; add:
Intent intent = new Intent(this, QRCodeScanActivity.class);
startActivityForResult(intent, QRCodeScanActivity.ACTIVITY_SCAN_CODE);
and you should have the necessary code to receive the result:
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == QRCodeScanActivity.ACTIVITY_SCAN_CODE) {
String textScanned = intent.getStringExtra("SCANNED");
....
}
}
That should work vey very well.
Regards,

ZXing PDF417 + ALL_CODE_TYPES

Using ZXing (on Android), if you initiate a PDF417 barcode scan like this...
List<String> oDesiredFormats = Arrays.asList("PDF_417".split(","));
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan(oDesiredFormats);
... and you initiate an "all codes" (except PDF417 and maybe a few others) barcode scan like this...
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
... then how do you initiate a single barcode scan that will recognise both (all the standard codes, and PDF417)? Thanks in advance!
If you don't specify it, it will default to scanning for whatever the user has configured. This by default includes most formats but not PDF417. So, I think you'd have to enumerate all the formats here. It's not too hard, but do you really want that? usually you have a use case that is scanning for a few related formats at most.

Zxing - My app does not want to start the camera

first of all i will introduce myself. I am a young student from austria who is new to Android programming. My Project is to write a Barcode scanner and if you scan a product you get more information about it.
So lets get started with the real problem now:
I have done everything what the tutorials say and it works. The ZXING-Source Code is now a libary for my own Project and ofcourse it is included.
When i export the Android project as a FILENAME.APK and copy it to my SGS3 everything works.
Then i install the apk on my phone and start running the app. When i press the scan barcode button which calls the "onClick"-Method it does nothing. Android says to me the application has ben stopped.
I dont know which function i have to use. Should i use the IntentIntegrator methods or the intent methods to be able to scan a code. ( I know i cant use both in my Method, pasted it here to show your my problem )
public void onClick(final View view)
{
IntentIntegrator integrator = new IntentIntegrator(this);
integrator.initiateScan();
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(intent, 0);
}
this integration is provided by intents,so you had to have installed app which runs with specific intent (action=com.google.zxing.client.android.SCAN) like Barcode Scanner
i'm pretty sure that you don't have such app on your other phone and thats why you're getting "activity not found" Exception now
Edit: about diffs between IntentIntegrator and plain Intent ... well, there is no diffs beside that with IntentIntegrator you have it all nicely wrapped

Categories

Resources