简体   繁体   English

Android如何从相机中捕获两个连续帧

[英]Android How to capture two consecutive frames from camera

I'm trying to program Optical flow on android device. 我正在尝试在Android设备上编程光流。 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. 我不确定这是正确的Java语法,只是在为其分配data之前复制currentFrame Anyway, I think you can also use the VideoCapture class to obtain the frames already in a Mat format. 无论如何,我认为你也可以使用VideoCapture类来获取Mat格式的帧。 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. 我不确定这个类在最新版本中是否仍然可用,但根据我使用Opencv 2.3的经验,使用它来抓取相机帧比使用Android相机要快得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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