title: Is the Open Sourced Google Vision API CameraSource class Out-Dated?
body: <p>In this <a href="https://stackoverflow.com/questions/32051973/google-vision-api-samples-get-the-camerasource-to-focus?rq=1">SO Thread</a>, <a href="https://stackoverflow.com/users/5231007/pm0733464">pm0733464</a>, says this: </p>
  
  <blockquote>
    <p>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:</p>
  </blockquote>
  
  <p>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. </p>
  
  <pre><code> 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();
  </code></pre>
  
  <p>In my experiments this "finds" barcodes much faster than using the processor that the examples show in the <a href="https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java" rel="nofollow noreferrer">Official Google Vision API Samples</a></p>
  
  <p>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?</p>
  
  <p>[EDIT] 
  Sharing code by request of pm0733464:</p>
  
  <p>For the record, I began with the fork of the vision api Demo which allows for <a href="https://github.com/wax911/Vision-Barcode-Scanner" rel="nofollow noreferrer">automatically detecting barcode</a></p>
  
  <p>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</p>
  
  <p>in  <strong>BarcodeCaptureActivity</strong> I change <strong>createCameraSource</strong> where it defined the barcode detector like to this:</p>
  
  <pre><code>  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 &gt;= 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();
      }
  </code></pre>
  
  <p>My FocusProcessor (in the same class) looks like this:</p>
  
  <pre><code>private class MyCameraFocusingProcessor implements Detector.Processor&lt;Barcode&gt;
      {
          public MyCameraFocusingProcessor(BarcodeDetector barcodeDetector, NullTracker emptyTracker)
          {
  
          }
  
          @Override
          public void release()
          {
  
          }
  
          @Override
          public void receiveDetections(Detector.Detections&lt;Barcode&gt; detections)
          {
              //  boolean chk = detections.detectorIsOperational();
              int sizeCheck = detections.getDetectedItems().size();
              if (sizeCheck &gt; 0)
              {
                  SparseArray&lt;Barcode&gt; codes = detections.getDetectedItems();
                  for (int i = 0; i &lt; 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
      {
  
      }
  </code></pre>