Skip to content Skip to sidebar Skip to footer

Android How To Capture Two Consecutive Frames From Camera

I'm trying to program Optical flow on android device. My problem is to get two consecutive frames from camera. That's the code to get ONE frame. mCamera.setPreviewCallback(new Pre

Solution 1:

Can't you then do something like:

privatebyte[] currFrame;
privatebyte[] prevFrame;    

privatevoidcopyFrame(byte[] a){
        if(a != null) prevFrame = a;
}

mCamera.setPreviewCallback(newPreviewCallback() {
            publicvoidonPreviewFrame(byte[] data, Camera camera) {
                synchronized (SampleViewBase.this) {
                    copyFrame(currFrame);              
                    currFrame = data;
                    SampleViewBase.this.notify();
                }
            }
        });  

I'm not sure that's proper Java syntax but just copy the currentFrame, before assigning data to it. Anyway, I think you can also use the VideoCapture class to obtain the frames already in a Mat format. I'm not sure if this class is still available in the latest release, but from my experience with Opencv 2.3 it was much faster to use it to grab camera frames than to use the Android camera.

Post a Comment for "Android How To Capture Two Consecutive Frames From Camera"