本文整理汇总了Java中com.google.android.gms.vision.barcode.BarcodeDetector类的典型用法代码示例。如果您正苦于以下问题:Java BarcodeDetector类的具体用法?Java BarcodeDetector怎么用?Java BarcodeDetector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BarcodeDetector类属于com.google.android.gms.vision.barcode包,在下文中一共展示了BarcodeDetector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createCameraSource
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
/**
* Creates and starts the camera. Note that this uses a higher resolution in comparison
* to other detection examples to enable the barcode detector to detect small barcodes
* at long distances.
*
* Suppressing InlinedApi since there is a check that the minimum version is met before using
* the constant.
*/
@SuppressLint("InlinedApi")
private void createCameraSource() {
// set preferred mBarcodeTypes before this :)
BarcodeDetector barcodeDetector = createBarcodeDetector();
if (!hasNecessaryCapabilities()) {
return;
}
// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the barcode detector to detect small barcodes
// at long distances.
mCameraSource = new CameraSource.Builder(mContext.getApplicationContext(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1600, 900)
.setRequestedFps(15.0f)
.setPreferredFocusModes(PREFERRED_FOCUS_MODES)
.build();
}
示例2: onCreate
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Iniciamos el detector de QR
detectorQR =
new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if (!detectorQR.isOperational()) {
Log.w(TAG, "No se ha podido crear el detector");
return;
}
ImageView iconoCamara = (ImageView) findViewById(R.id.iconoCamara);
iconoCamara.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tomarFoto();
}
});
}
示例3: createCameraSource
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
/**
* Creates and starts the camera. Note that this uses a higher resolution in comparison
* to other detection examples to enable the barcode detector to detect small barcodes
* at long distances.
* <p>
* Suppressing InlinedApi since there is a check that the minimum version is met before using
* the constant.
*/
@SuppressLint("InlinedApi")
private void createCameraSource(boolean autoFocus, boolean useFlash) {
Context context = getApplicationContext();
// A barcode detector is created to track barcodes. An associated multi-processor instance
// is set to receive the barcode detection results, track the barcodes, and maintain
// graphics for each barcode on screen. The factory is used by the multi-processor to
// create a separate tracker instance for each barcode.
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context)
.build();
BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this);
barcodeDetector.setProcessor(
new MultiProcessor.Builder<>(barcodeFactory).build());
if (!barcodeDetector.isOperational()) {
// Note: The first time that an app using the barcode or face API is installed on a
// device, GMS will download a native libraries to the device in order to do detection.
// Usually this completes before the app is run for the first time. But if that
// download has not yet completed, then the above call will not detect any barcodes
// and/or faces.
//
// isOperational() can be used to check if the required native libraries are currently
// available. The detectors will automatically become operational once the library
// downloads complete on device.
// Check for low storage. If there is low storage, the native library will not be
// downloaded, so detection will not become operational.
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
if (hasLowStorage) {
Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
}
}
// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the barcode detector to detect small barcodes
// at long distances.
CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1600, 1024)
.setRequestedFps(15.0f);
// make sure that auto focus is an available option
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
builder = builder.setFocusMode(
autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null);
}
mCameraSource = builder
.setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null)
.build();
}
示例4: createCameraSource
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
/**
* Creates and starts the camera. Note that this uses a higher resolution in comparison
* to other detection examples to enable the barcode detector to detect small barcodes
* at long distances.
* <p>
* Suppressing InlinedApi since there is a check that the minimum version is met before using
* the constant.
*/
@SuppressLint("InlinedApi")
private void createCameraSource(boolean autoFocus, boolean useFlash) {
Log.e(TAG, "createCameraSource:");
Context context = getActivity();
// A barcode detector is created to track barcodes. An associated multi-processor instance
// is set to receive the barcode detection results, track the barcodes, and maintain
// graphics for each barcode on screen. The factory is used by the multi-processor to
// create a separate tracker instance for each barcode.
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this);
barcodeDetector.setProcessor(
new MultiProcessor.Builder<>(barcodeFactory).build());
if (!barcodeDetector.isOperational()) {
// Note: The first time that an app using the barcode or face API is installed on a
// device, GMS will download a native libraries to the device in order to do detection.
// Usually this completes before the app is run for the first time. But if that
// download has not yet completed, then the above call will not detect any barcodes
// and/or faces.
//
// isOperational() can be used to check if the required native libraries are currently
// available. The detectors will automatically become operational once the library
// downloads complete on device.
Log.w(TAG, "Detector dependencies are not yet available.");
// Check for low storage. If there is low storage, the native library will not be
// downloaded, so detection will not become operational.
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
boolean hasLowStorage = getActivity().registerReceiver(null, lowstorageFilter) != null;
if (hasLowStorage) {
Toast.makeText(getActivity(), R.string.low_storage_error, Toast.LENGTH_LONG).show();
Log.w(TAG, getString(R.string.low_storage_error));
}
}
// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the barcode detector to detect small barcodes
// at long distances.
CameraSource.Builder builder = new CameraSource.Builder(getActivity(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1600, 1024)
.setRequestedFps(15.0f);
// make sure that auto focus is an available option
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
builder = builder.setFocusMode(
autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null);
}
mCameraSource = builder
.setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null)
.build();
}
示例5: createCameraSource
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
/**
* Creates and starts the camera.
*
* Suppressing InlinedApi since there is a check that the minimum version is met before using
* the constant.
*/
@SuppressLint("InlinedApi")
private void createCameraSource(boolean autoFocus, boolean useFlash) {
Context context = getApplicationContext();
// A barcode_capture detector is created to track barcodes. An associated multi-processor instance
// is set to receive the barcode_capture detection results, track the barcodes, and maintain
// graphics for each barcode_capture on screen. The factory is used by the multi-processor to
// create a separate tracker instance for each barcode_capture.
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context)
.setBarcodeFormats(Barcode.ALL_FORMATS)
.build();
BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(this);
barcodeDetector.setProcessor(new MultiProcessor.Builder<>(barcodeFactory).build());
if (!barcodeDetector.isOperational()) {
// Note: The first time that an app using the barcode_capture or face API is installed on a
// device, GMS will download a native libraries to the device in order to do detection.
// Usually this completes before the app is run for the first time. But if that
// download has not yet completed, then the above call will not detect any barcodes
// and/or faces.
//
// isOperational() can be used to check if the required native libraries are currently
// available. The detectors will automatically become operational once the library
// downloads complete on device.
Log.w(TAG, "Detector dependencies are not yet available.");
// Check for low storage. If there is low storage, the native library will not be
// downloaded, so detection will not become operational.
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
if (hasLowStorage) {
Toast.makeText(this, R.string.low_storage_error,
Toast.LENGTH_LONG).show();
Log.w(TAG, getString(R.string.low_storage_error));
}
}
// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the barcode_capture detector to detect small barcodes
// at long distances.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(metrics.widthPixels, metrics.heightPixels)
.setRequestedFps(24.0f);
// make sure that auto focus is an available option
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
builder = builder.setFocusMode(
autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null);
}
mCameraSource = builder
.setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null)
.build();
}
示例6: createCameraSource
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
/**
* Creates and starts the camera. Note that this uses a higher resolution in comparison
* to other detection examples to enable the barcode detector to detect small barcodes
* at long distances.
*
* Suppressing InlinedApi since there is a check that the minimum version is met before using
* the constant.
*/
@SuppressLint("InlinedApi")
private void createCameraSource(boolean autoFocus) {
Context context = getApplicationContext();
// A barcode detector is created to track barcodes. An associated multi-processor instance
// is set to receive the barcode detection results, track the barcodes, and maintain
// graphics for each barcode on screen. The factory is used by the multi-processor to
// create a separate tracker instance for each barcode.
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build();
BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay,this);
barcodeDetector.setProcessor(
new MultiProcessor.Builder<Barcode>(barcodeFactory).build());
if (!barcodeDetector.isOperational()) {
// Note: The first time that an app using the barcode or face API is installed on a
// device, GMS will download a native libraries to the device in order to do detection.
// Usually this completes before the app is run for the first time. But if that
// download has not yet completed, then the above call will not detect any barcodes
// and/or faces.
//
// isOperational() can be used to check if the required native libraries are currently
// available. The detectors will automatically become operational once the library
// downloads complete on device.
Log.w(TAG, "Detector dependencies are not yet available.");
// Check for low storage. If there is low storage, the native library will not be
// downloaded, so detection will not become operational.
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
if (hasLowStorage) {
Toast.makeText(this, "Face detector dependencies cannot be downloaded due to low device storage", Toast.LENGTH_LONG).show();
Log.w(TAG, "Face detector dependencies cannot be downloaded due to low device storage");
}
}
// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the barcode detector to detect small barcodes
// at long distances.
CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1600, 960)
.setRequestedFps(15.0f);
// make sure that auto focus is an available option
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
builder = builder.setFocusMode(
autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO : null);
}
mCameraSource = builder.build();
}
示例7: createBarcodeDetector
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
private BarcodeDetector createBarcodeDetector() {
// A barcode detector is created to track barcodes. An associated multi-processor instance
// is set to receive the barcode detection results, and track the barcodes.
// The factory is used by the multi-processor to
// create a separate tracker instance for each barcode.
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(mContext)
.setBarcodeFormats(mBarcodeTypes)
.build();
barcodeDetector.setProcessor(new MultiProcessor.Builder<>(this).build());
return mBarcodeDetector = barcodeDetector;
}
示例8: scanBitmap
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
public static void scanBitmap(Context context, Bitmap bitmap, int barcodeFormat, BarcodeRetriever barcodeRetriever) {
BarcodeDetector detector =
new BarcodeDetector.Builder(context)
.setBarcodeFormats(barcodeFormat)
.build();
if (!detector.isOperational()) {
barcodeRetriever.onRetrievedFailed("Could not set up the detector!");
// txtView.setText("Could not set up the detector!");
return;
}
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
barcodeRetriever.onBitmapScanned(detector.detect(frame));
}
示例9: getCustomBarcodeDetector
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
public Detector<Barcode> getCustomBarcodeDetector() {
if (barcodeDetector == null)
barcodeDetector = new BarcodeDetector.Builder(getContext())
.setBarcodeFormats(getBarcodeFormat())
.build();
return customBarcodeDetector == null ? barcodeDetector : customBarcodeDetector;
}
示例10: onCreate
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
scanResults = (TextView) findViewById(R.id.scan_results);
if (savedInstanceState != null) {
imageUri = Uri.parse(savedInstanceState.getString(SAVED_INSTANCE_URI));
scanResults.setText(savedInstanceState.getString(SAVED_INSTANCE_RESULT));
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_PERMISSION);
}
});
detector = new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.DATA_MATRIX | Barcode.QR_CODE)
.build();
if (!detector.isOperational()) {
scanResults.setText("Could not set up the detector!");
return;
}
}
示例11: buildMobileVisionBarcodeDetector
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
/**
* Build a barcode scanner using the Mobile Vision Barcode API
*/
private void buildMobileVisionBarcodeDetector() {
String focusMode = Camera.Parameters.FOCUS_MODE_FIXED;
if(mAutoFocusEnabled){
focusMode = Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE;
}
mBarcodeDetector = new BarcodeDetector.Builder(mActivity)
.setBarcodeFormats(mBarcodeFormats)
.build();
mCameraSource = new CameraSource.Builder(mActivity, mBarcodeDetector)
.setFacing(mFacing)
.setFlashMode(mFlashEnabledByDefault ? Camera.Parameters.FLASH_MODE_TORCH : null)
.setFocusMode(focusMode)
.build();
}
示例12: onCreate
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBarcodeDetector = new BarcodeDetector.Builder(getActivity())
.setBarcodeFormats(Barcode.QR_CODE)
.build();
mCameraSource = new CameraSource.Builder(getActivity(), mBarcodeDetector).build();
}
示例13: getBarcodeDetector
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
/**
* Gets barcode detector.
*
* @param context
* the context
* @return the barcode detector
*/
static BarcodeDetector getBarcodeDetector(Context context) {
if (detector == null) {
detector = new BarcodeDetector.Builder(context.getApplicationContext()).setBarcodeFormats(
Barcode.QR_CODE).build();
}
return detector;
}
示例14: createCameraSource
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
public void createCameraSource() {
//Setup the BarCodeDetector
Context context = getApplicationContext();
BarcodeDetector detector = new BarcodeDetector.Builder(context)
.build();
//note the barcodeTrackerFactory is defined below and is very simple.
detector.setProcessor(new MultiProcessor.Builder<>(new BarcodeTrackFactory()).build());
if (!detector.isOperational()) {
// Note: The first time that an app using face API is installed on a device, GMS will
// download a native library to the device in order to do detection. Usually this
// completes before the app is run for the first time. But if that download has not yet
// completed, then the above call will not detect any faces.
//
// isOperational() can be used to check if the required native library is currently
// available. The detector will automatically become operational once the library
// download completes on device.
Log.w(TAG, "Face detector dependencies are not yet available.");
}
// Creates and starts the camera. Note that this uses a higher resolution in comparison
// to other detection examples to enable the barcode detector to detect small barcodes
// at long distances.
CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), detector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1600, 1024)
.setRequestedFps(15.0f);
builder = builder.setAutoFocusEnabled(true);
mCameraSource = builder.build();
}
示例15: getText
import com.google.android.gms.vision.barcode.BarcodeDetector; //导入依赖的package包/类
public static String getText(Context innercontext, Bitmap bitmap) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
Bitmap compressed = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
Frame newFrame = new Frame.Builder()
.setBitmap(compressed)
.build();
//initialize Textrecognizer
BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(innercontext).build();
TextRecognizer textRecognizer = new TextRecognizer.Builder(innercontext).build();
//parse text
MultiDetector multiDetector = new MultiDetector.Builder()
.add(barcodeDetector)
.add(textRecognizer)
.build();
SparseArray<Object> objectSparseArray = multiDetector.detect(newFrame);
ArrayList<LineAttributes> lineAttributes = new ArrayList<>();
for (int i = 0; i < objectSparseArray.size(); i++) {
Object currObject = objectSparseArray.valueAt(i);
if (currObject instanceof TextBlock) {
TextBlock item = (TextBlock) currObject;
List<Line> lines = (List<Line>) ((TextBlock) currObject).getComponents();
for(Line elements: lines){
RectF rect = new RectF(elements.getBoundingBox());
float height = rect.bottom - rect.top;
LineAttributes attr = new LineAttributes(rect.left, rect.top, rect.right, rect.bottom, elements.getValue(), height, false);
lineAttributes.add(attr);
}
}
}
multiDetector.release();
textRecognizer.release();
barcodeDetector.release();
Collections.sort(lineAttributes, new Comparator<LineAttributes>() {
@Override
public int compare(LineAttributes o1, LineAttributes o2) {
return (Float.compare(o1.getTop(), o2.getTop()));
}
});
StringBuilder sb = new StringBuilder();
for (LineAttributes line : lineAttributes) {
sb.append(line.getText());
sb.append("\n");
}
return (sb.toString());
}