Glass camera preview display is garbled
Asked Answered
A

1

7

I am trying to get a live camera preview to display in Google Glass.

I'm using all of the camera defaults (and have also tried using a few different image formats; ideally, I can use one of the YUV formats), but the image that shows up in the display is garbled, like this:

garbled preview image

The layout is simple:

<?xml version="1.0" encoding="utf-8"?>
<TextureView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scan_preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

Here is the Activity code:

public class ScanActivity extends Activity {
    private static final String kTag = ScanActivity.class.getSimpleName();
    private TextureView mVideoCaptureView = null;
    private Camera mCamera = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_scan);
        setTitle(R.string.title_scan);

        mVideoCaptureView = (TextureView) findViewById(R.id.scan_preview);
        mVideoCaptureView.setKeepScreenOn(true);
        mVideoCaptureView.setSurfaceTextureListener(new VideoCaptureTextureListener());
    }

    @Override
    protected void onPause() {
        super.onPause();
        stopVideo();
    }

    @Override
    protected void onResume() {
        super.onResume();
        startVideo();
    }

    private void startVideo() {
        if (mCamera != null) {
            mCamera.release();
        }
        mCamera = Camera.open();
        if (null != mVideoCaptureView) {
            try {
                mCamera.setPreviewTexture(mVideoCaptureView.getSurfaceTexture());
            } catch (IOException e) {
                Log.e(kTag, "Error setting preview texture", e);
                return;
            }
        }
        mCamera.startPreview();
    }

    private void stopVideo() {
        if (null == mCamera)
            return;
        try {
            mCamera.stopPreview();
            mCamera.setPreviewDisplay(null);
            mCamera.setPreviewTexture(null);
            mCamera.release();
        } catch (IOException e) {
            Log.w(kTag, e);
        }
        mCamera = null;
    }

    private final class VideoCaptureTextureListener implements TextureView.SurfaceTextureListener {

        @Override
        public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
            stopVideo();
            return true;
        }

        @Override
        public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
            startVideo();
        }

        @Override
        public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
        }

        @Override
        public void onSurfaceTextureUpdated(SurfaceTexture surface) {
        }
    }
}

Do you have any idea why this completely unmanipulated camera preview is not displaying correctly?

Agglutinogen answered 13/12, 2013 at 1:42 Comment(1)
possible duplicate of Google Glass preview image scrambled with new XE10 releaseSaari
I
10

This has been answered here: https://mcmap.net/q/529028/-google-glass-preview-image-scrambled-with-new-xe10-release

Longterm:

Camera.Parameters params = camera.getParameters();
params.setPreviewFpsRange(30000, 30000);
camera.setParameters(params);

Shorterm(testing):

For quick testing and usage, simply add to your outermost view:

android:layout_margin="1dp"

For example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_margin="1dp"
    android:layout_height="match_parent" >

    <org.opencv.android.JavaCameraView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/tutorial2_activity_surface_view" />

</LinearLayout>
Insurrection answered 13/12, 2013 at 2:57 Comment(7)
When querying the camera, the maximum previewFpsRange is listed as 60000. I guess it's worth checking on next release.Agglutinogen
Still broken as of XE12.Agglutinogen
@slugchewer Definitely not, I was just working on my Camera app yesterday. Please look at: github.com/jaredsburrows/OpenQuartz/tree/master/example-appsInsurrection
Interesting. I am still seeing the bug. Supported preview rates are listed as 5-5k, 10-10k, 15-15k, 20-20k, 24-24k, 15-30k, 30-30k, 60-60k. The default is 60k, and it has that problem. If I manually choose 30-30k, as I was doing before, everything works fine. Did you notice a change in behavior with XE12 with no changes to your code?Agglutinogen
No. Here is my example code and applications I have made: github.com/jaredsburrows/OpenQuartz/tree/master/example-apps.Insurrection
This solved my problem and I just got the latest firmware update today.Viipuri
Anyone using OpenCV 2.4.9 can put "params.setPreviewFpsRange(30000, 30000);" around line 157 of src/org/opencv/android/JavaCameraView.java to get the OpenCV Tutorial 1 - Camera Preview sample project working.Prandial

© 2022 - 2024 — McMap. All rights reserved.