Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to capture two consecutive frames from camera

Tags:

android

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();
            }
        }
    });     
like image 289
h4p0 Avatar asked Mar 29 '26 00:03

h4p0


1 Answers

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.

like image 87
MobileCushion Avatar answered Mar 31 '26 05:03

MobileCushion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!