1

I am trying to integrate a qr code scanner into my google cardboard program. I have used the answer here to start a cardboard camera. I am encountering problems when I try to integrate the vision API for barcode reader into this. I need to start camera passing a texture to the vision API's camerasource portion.

final CameraSource cameraSource = new CameraSource
            .Builder(this, barcodeDetector)
            .setRequestedPreviewSize(640, 480)
            .build();

How do I integrate the qr code scanner with vision API into my cardboard app?

Community
  • 1
  • 1
Vasudha
  • 19
  • 5

1 Answers1

0

Google has provided a supremely useful View for managing your CameraSource for preview and detection. You don't have to worry about managing the texture itself or determining the layout of the texture/surface in your view.

It's called CameraSourcePreview, and it's used to manage the operation of your CameraSource along with a SurfaceView.

You can use the CameraSourcePreview like any other view in your layout, for example in this full screen LinearLayout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

  <com.google.android.gms.samples.vision.barcodereader.ui.camera.CameraSourcePreview
      android:id="@+id/preview"
      android:layout_width="match_parent"
      android:layout_height="match_parent">   
  </com.google.android.gms.samples.vision.barcodereader.ui.camera.CameraSourcePreview>

</LinearLayout>

And in your activity you set up your BarcodeDetector and CameraSource like normal (probably in your onCreate() method) and then (likely onResume()) start your CameraSourcePreview. It would look something like this:

if (mCameraSource != null) {
   try {
       mPreview.start(mCameraSource, mGraphicOverlay);
   } catch (IOException e) {
       Log.e(TAG, "Unable to start camera source.", e);
       mCameraSource.release();
       mCameraSource = null;
   }
}

So really, you'll just be managing your CameraSource through your the CameraSourcePreview, but it handles a lot of the heavy lifting of the layout/preview/etc. so you don't have to. Check out the BarcodeCaptureActivity to see more about how the activity manages these components.

Check out the barcode-reader sample in the android vision sample projects for the complete project sample.

Hope that helps, cheers.

robotsquidward
  • 163
  • 2
  • 16