use of com.google.android.gms.vision.MultiDetector in project android-vision by googlesamples.
the class MultiTrackerActivity method createCameraSource.
/**
* 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.
*/
private void createCameraSource() {
Context context = getApplicationContext();
// A face detector is created to track faces. An associated multi-processor instance
// is set to receive the face detection results, track the faces, and maintain graphics for
// each face on screen. The factory is used by the multi-processor to create a separate
// tracker instance for each face.
FaceDetector faceDetector = new FaceDetector.Builder(context).build();
FaceTrackerFactory faceFactory = new FaceTrackerFactory(mGraphicOverlay);
faceDetector.setProcessor(new MultiProcessor.Builder<>(faceFactory).build());
// 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);
barcodeDetector.setProcessor(new MultiProcessor.Builder<>(barcodeFactory).build());
// A multi-detector groups the two detectors together as one detector. All images received
// by this detector from the camera will be sent to each of the underlying detectors, which
// will each do face and barcode detection, respectively. The detection results from each
// are then sent to associated tracker instances which maintain per-item graphics on the
// screen.
MultiDetector multiDetector = new MultiDetector.Builder().add(faceDetector).add(barcodeDetector).build();
if (!multiDetector.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, 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.
mCameraSource = new CameraSource.Builder(getApplicationContext(), multiDetector).setFacing(CameraSource.CAMERA_FACING_BACK).setRequestedPreviewSize(1600, 1024).setRequestedFps(15.0f).build();
}
Aggregations