1

I've tried to implement this solution by adding a new class named JView to override JavaCV's initializeCamera. I'm trying to use this override function to do camera param setup. However, I found this override function seems not to be invoked? My class is as following and the face detection sample code (MainActivity) are from Space150

package com.space150.android.glass.opencvfacedetection;

import org.opencv.android.JavaCameraView;

import android.content.Context;
import android.hardware.Camera;
import android.util.AttributeSet;
import android.util.Log;

public class JView extends JavaCameraView {

    public JView(Context context, int cameraId) {
        super(context, cameraId);
    }

    public JView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    @Override
    protected boolean initializeCamera(int width, int height) 
    {
        Log.i("JVIEW", "initialize Camera");
        super.initializeCamera(width, height);

        Camera.Parameters params = mCamera.getParameters();

        // Post XE10 Hotfix
        params.setPreviewFpsRange(60000,60000);
        params.setPreviewSize(320,240);
        mCamera.setParameters(params);

        return true;
    }

}

Also, anyone has experiencing and solved the glitch camera preview problem on Glass XE16.11?

Thanks!

Community
  • 1
  • 1
mamahow
  • 21
  • 2
  • 3

1 Answers1

1

Your frame rate is too high in your setPreviewFPSRange call. You are at 60FPS. I have tested the below code at 5 and 30 FPS and it works.

When you see the glitch, it looks like this:

enter image description here

Here is my entire surfaceChanged method which works on XE16.11. Using this code there is no glitch as above, I see a normal preview.

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        if (mCamera == null) return;

        Camera.Parameters camParameters = mCamera.getParameters();
        //start glass fix - use 5000 instead of 30000 for better battery performance
        camParameters.setPreviewFpsRange(30000, 30000);
        //end glass fix
        camParameters.setPreviewSize(1920, 1080);
        camParameters.setPictureSize(2592, 1944);
        mCamera.setParameters(camParameters);
        try {
            mCamera.startPreview();
        } catch (Exception e) {
            mCamera.release();
            mCamera = null;
        }
    }
Mark Scheel
  • 2,963
  • 1
  • 20
  • 23
  • Hi, I'm trying to integrate [this](https://github.com/space150/google-glass-playground/tree/master/OpenCVFaceDetection) example, however, I have problem to get mCamera. What I've tried is to use mCamera = Camera.open() in surfaceChanged(). check my [gist](https://gist.github.com/harryhow/c8f7bc3d48842b5fe362) also... – mamahow Apr 30 '14 at 07:14
  • please check my code [here](https://gist.github.com/harryhow/c8f7bc3d48842b5fe362) I put Camera.open() in surfaceCreated(), set cam parameters in surfaceChanged(). I also try to put 0 or -1 as parameter to open camera but still without good luck. What I suspect from the log is this example using OpenCV's CameraBridgeViewBase as a client bridge between Android Cam and Open CV to init camera. That means if we open camera before BaseLoaderCallback(), the mOpenCvCameraView.enableView() in BaseLoaderCallback() won't work because camera resource has been occupied. :/ Any thoughts? – mamahow May 01 '14 at 01:27
  • Put this in onResume: mCamera = Camera.open(0); and then put this in onPause: if (mCamera != null) { mCamera.release(); mCamera = null; } – Mark Scheel May 01 '14 at 04:06