简体   繁体   中英

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 PreviewCallback() {
        public void onPreviewFrame(byte[] data, Camera camera) {
            synchronized (SampleViewBase.this) {
                mFrame2 = data;
                SampleViewBase.this.notify();
            }
        }
    });     

Can't you then 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'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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM