Android How to capture two consecutive frames from the camera

I am trying to program an optical stream on an Android device. My problem is to get two consecutive frames from the camera.

So that the code receives ONE frame.

mCamera.setPreviewCallback(new PreviewCallback() {
        public void onPreviewFrame(byte[] data, Camera camera) {
            synchronized (SampleViewBase.this) {
                mFrame2 = data;
                SampleViewBase.this.notify();
            }
        }
    });     
+3
source share
1 answer

Can't you do something like:

private byte[] currFrame;
private byte[] prevFrame;    

private void copyFrame(byte[] a){
        if(a != null) prevFrame = a;
}

mCamera.setPreviewCallback(new PreviewCallback() {
            public void onPreviewFrame(byte[] data, Camera camera) {
                synchronized (SampleViewBase.this) {
                    copyFrame(currFrame);              
                    currFrame = data;
                    SampleViewBase.this.notify();
                }
            }
        });  

I am not sure if the correct syntax is Java, but just copy currentFramebefore assigning it to it data. In any case, I think you can also use the class VideoCaptureto get frames already in the format Mat. I'm not sure if this class is still available in the latest version, but from my experience with Opencv 2.3 it was much faster to use it to capture camera frames than to use an Android camera.

+1