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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With