In this SO Thread, pm0733464, says this:
we open sourced the CameraSource class, which has an auto focus method as well. This one allows you to set a specific focus mode as opposed to the "continuous video" mode that the official API defaults to:
Which was great. But it seems that the Google Vision API has moved on and the open Sourced version has not. The official API now has a new type of processor called: FocusingProcessor -- which allows the detector to only respond on the OnFocus event.
barcodeDetector = new BarcodeDetector.Builder(this)
.setBarcodeFormats(Barcode.QR_CODE | Barcode.PDF417)
.build();
barcodeDetector.setProcessor(new BarcodeFocusingProcessor(
barcodeDetector,
new NullTracker()));
CameraSource.Builder builder = new CameraSource.Builder(getApplicationContext(), barcodeDetector)
.setFacing(CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1600, 1024)
.setAutoFocusEnabled(true)
.setRequestedFps(24.0f);
cameraSource = builder.build();
In my experiments this "finds" barcodes much faster than using the processor that the examples show in the Official Google Vision API Samples
Am I missing something somewhere? Or is the CameraSource in the Google.Vision libraries not the same one they are showing in the open source?
[EDIT] Sharing code by request of pm0733464:
For the record, I began with the fork of the vision api Demo which allows for automatically detecting barcode
My code makes some simple changes. First off, I add PDF417 to the scanable barcodes. Then I set the processor to an autofocus-er. I turn the tracker into a nullTracker because I don't need the graphic displaying, and I hoped that would speed some things up
in BarcodeCaptureActivity I change createCameraSource where it defined the barcode detector like to this:
BarcodeDetector barcodeDetector =
new BarcodeDetector.Builder(context)
.setBarcodeFormats(Barcode.PDF417)
.build();
barcodeDetector.setProcessor(new MyCameraFocusingProcessor(
barcodeDetector,
new NullTracker()));
// 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(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();
}
My FocusProcessor (in the same class) looks like this:
private class MyCameraFocusingProcessor implements Detector.Processor<Barcode>
{
public MyCameraFocusingProcessor(BarcodeDetector barcodeDetector, NullTracker emptyTracker)
{
}
@Override
public void release()
{
}
@Override
public void receiveDetections(Detector.Detections<Barcode> detections)
{
// boolean chk = detections.detectorIsOperational();
int sizeCheck = detections.getDetectedItems().size();
if (sizeCheck > 0)
{
SparseArray<Barcode> codes = detections.getDetectedItems();
for (int i = 0; i < sizeCheck; i++)
{
Barcode barcode = codes.valueAt(i);
try
{
if (barcode.format == Barcode.PDF417)
{
Intent data = new Intent();
data.putExtra(BarcodeObject, barcode);
setResult(CommonStatusCodes.SUCCESS, data);
finish();
break;
}
}
catch (Exception ex)
{
Log.d("Detect", "Error: " + ex.getMessage());
}
}
}
return;
}
}
private class NullTracker
{
}