二维码识别仓库,zxing、zbar、Google Vision三合一
|
|
5 rokov pred | |
|---|---|---|
| core | 5 rokov pred | |
| gradle | 5 rokov pred | |
| vision | 5 rokov pred | |
| vision-sample | 5 rokov pred | |
| zbar | 5 rokov pred | |
| zbar-sample | 5 rokov pred | |
| zxing | 5 rokov pred | |
| zxing-sample | 5 rokov pred | |
| .gitignore | 5 rokov pred | |
| CHANGELOG.md | 5 rokov pred | |
| LICENSE | 5 rokov pred | |
| README.md | 5 rokov pred | |
| build.gradle | 5 rokov pred | |
| dependencies.gradle | 5 rokov pred | |
| gradlew | 5 rokov pred | |
| gradlew.bat | 5 rokov pred | |
| settings.gradle | 5 rokov pred |
原仓库: https://github.com/dm77/barcodescanner/tree/TonyTangAndroid-master
Android library projects that provides easy to use and extensible Barcode Scanner views based on ZXing and ZBar.
Version 1.8.4 introduces a couple of new changes:
Add the following dependency to your build.gradle file.
compile 'me.dm7.barcodescanner:vision:1.9'
1.) Add camera permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.CAMERA" />
2.) A very basic activity would look like this:
package me.dm7.barcodescanner.vision.sample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import me.dm7.barcodescanner.vision.BarcodeFormat;
import me.dm7.barcodescanner.vision.Result;
import me.dm7.barcodescanner.vision.VisionScannerView;
public class SimpleScannerActivity extends Activity implements VisionScannerView.ResultHandler {
private static final String TAG = "SimpleScannerActivity";
private VisionScannerView mScannerView;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new VisionScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
}
@Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
@Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v(TAG, rawResult.getBarcode().displayValue); // Prints scan results
Log.v(TAG, BarcodeFormat.getFormatById(rawResult.getBarcode().format).toString()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
Toast.makeText(SimpleScannerActivity.this, rawResult.getBarcode().displayValue, Toast.LENGTH_SHORT).show();
}
}
Please take a look at the vision-sample project for a full working example.
Take a look at the FullScannerActivity.java classes to get an idea on advanced usage.
Interesting methods on the VisionScannerView include:
// Toggle flash:
void setFlash(boolean);
// Toogle autofocus:
void setAutoFocus(boolean);
// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);
// Specify the cameraId to start with:
void startCamera(int cameraId);
Specify front-facing or rear-facing cameras by using the void startCamera(int cameraId); method.
Supported Formats:
BarcodeFormat.CODE_128
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODABAR
BarcodeFormat.DATA_MATRIX
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.ITF
BarcodeFormat.QR_CODE
BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.PDF417
BarcodeFormat.AZTEC
Add the following dependency to your build.gradle file.
compile 'me.dm7.barcodescanner:zxing:1.9.2'
1.) Add camera permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.CAMERA" />
2.) A very basic activity would look like this:
public class SimpleScannerActivity extends Activity implements ZXingScannerView.ResultHandler {
private ZXingScannerView mScannerView;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZXingScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
}
@Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
@Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v(TAG, rawResult.getText()); // Prints scan results
Log.v(TAG, rawResult.getBarcodeFormat().toString()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
}
}
Please take a look at the zxing-sample project for a full working example.
Take a look at the ScannerActivity.java or ScannerFragment.java classes to get an idea on advanced usage.
Interesting methods on the ZXingScannerView include:
// Toggle flash:
void setFlash(boolean);
// Toogle autofocus:
void setAutoFocus(boolean);
// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);
// Specify the cameraId to start with:
void startCamera(int cameraId);
Specify front-facing or rear-facing cameras by using the void startCamera(int cameraId); method.
Supported Formats:
BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.RSS_14
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODE_128
BarcodeFormat.ITF
BarcodeFormat.CODABAR
BarcodeFormat.QR_CODE
BarcodeFormat.DATA_MATRIX
BarcodeFormat.PDF_417
Add the following dependency to your build.gradle file.
compile 'me.dm7.barcodescanner:zbar:1.9.2'
1.) Add camera permission to your AndroidManifest.xml file:
<uses-permission android:name="android.permission.CAMERA" />
2.) A very basic activity would look like this:
public class SimpleScannerActivity extends Activity implements ZBarScannerView.ResultHandler {
private ZBarScannerView mScannerView;
@Override
public void onCreate(Bundle state) {
super.onCreate(state);
mScannerView = new ZBarScannerView(this); // Programmatically initialize the scanner view
setContentView(mScannerView); // Set the scanner view as the content view
}
@Override
public void onResume() {
super.onResume();
mScannerView.setResultHandler(this); // Register ourselves as a handler for scan results.
mScannerView.startCamera(); // Start camera on resume
}
@Override
public void onPause() {
super.onPause();
mScannerView.stopCamera(); // Stop camera on pause
}
@Override
public void handleResult(Result rawResult) {
// Do something with the result here
Log.v(TAG, rawResult.getContents()); // Prints scan results
Log.v(TAG, rawResult.getBarcodeFormat().getName()); // Prints the scan format (qrcode, pdf417 etc.)
// If you would like to resume scanning, call this method below:
mScannerView.resumeCameraPreview(this);
}
}
Please take a look at the zbar/sample project for a full working example.
Take a look at the ScannerActivity.java or ScannerFragment.java classes to get an idea on advanced usage.
Interesting methods on the ZBarScannerView include:
// Toggle flash:
void setFlash(boolean);
// Toogle autofocus:
void setAutoFocus(boolean);
// Specify interested barcode formats:
void setFormats(List<BarcodeFormat> formats);
Specify front-facing or rear-facing cameras by using the void startCamera(int cameraId); method.
Supported Formats:
BarcodeFormat.PARTIAL
BarcodeFormat.EAN8
BarcodeFormat.UPCE
BarcodeFormat.ISBN10
BarcodeFormat.UPCA
BarcodeFormat.EAN13
BarcodeFormat.ISBN13
BarcodeFormat.I25
BarcodeFormat.DATABAR
BarcodeFormat.DATABAR_EXP
BarcodeFormat.CODABAR
BarcodeFormat.CODE39
BarcodeFormat.PDF417
BarcodeFormat.QR_CODE
BarcodeFormat.CODE93
BarcodeFormat.CODE128
mkdir some_work_dir
cd work_dir
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
Patch the localcharset.c file: vim libiconv-1.14/libcharset/lib/localcharset.c
On line 48, add the following line of code:
#undef HAVE_LANGINFO_CODESET
Save the file and continue with steps below:
cd libiconv-1.14
./configure
cd ..
hg clone http://hg.code.sf.net/p/zbar/code zbar-code
cd zbar-code/android
android update project -p . -t 'android-19'
Open jni/Android.mk file and add fPIC flag to LOCAL_C_FLAGS. Open jni/Application.mk file and specify APP_ABI targets as needed.
ant -Dndk.dir=$NDK_HOME -Diconv.src=some_work_dir/libiconv-1.14 zbar-clean zbar-all
Upon completion you can grab the .so and .jar files from the libs folder.
Almost all of the code for these library projects is based on:
https://github.com/dm77/barcodescanner/graphs/contributors
Apache License, Version 2.0