使用Android如何捕获从相机两个连续帧 [英] Android How to capture two consecutive frames from camera
问题描述
我想程序的Android设备上的光流。
我的问题是,从相机的两个连续的帧。
这就是code得到一个框架。
mCamera.set previewCallback(新previewCallback(){
在previewFrame(字节[]数据,相机摄像头){公共无效
同步(SampleViewBase.this){
mFrame2 =数据;
SampleViewBase.this.notify();
}
}
});
你不能再这样做:
专用字节[] currFrame;
私人字节[] prevFrame;私人无效copyFrame(字节[] A){
如果(一个!= NULL)prevFrame =一个;
}mCamera.set previewCallback(新previewCallback(){
在previewFrame(字节[]数据,相机摄像头){公共无效
同步(SampleViewBase.this){
copyFrame(currFrame);
currFrame =数据;
SampleViewBase.this.notify();
}
}
});
我不知道这是正确的Java语法,但只是在设置currentFrame
,分配前数据
复制到其中。无论如何,我想你也可以使用 VideoCapture
类已经获得帧在垫
格式。我不知道这是否是类在最新版本中仍然可以使用,但是从我用opencv实现2.3的经验是要快得多用它来抓取摄像头帧,而不是使用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();
}
}
});
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.
这篇关于使用Android如何捕获从相机两个连续帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!