用android Camera2连续拍摄静态照片 [英] Continuously take still photo with android Camera2
问题描述
在 Camera2Basic 示例中,我修改了代码以使程序连续拍摄每张照片2秒它运行正常,但过一会儿进入了相同的状态回调条件,并且不再拍照:
From Camera2Basic example, I modified the code to make the program continuously takes still photo every 2 seconds. It runs fine but after a while it enters the same statecallback condition and does not take picture anymore:
case STATE_WAITING_PRECAPTURE: {
// CONTROL_AE_STATE can be null on some devices
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
mState = STATE_WAITING_NON_PRECAPTURE;
}
else
{
Log.e(TAG,"aeState = " + aeState);
}
break;
}
日志继续打印aeState = 2,即CONTROL_AE_STATE_CONVERGED.我的问题是,为什么在AE收敛时代码不执行任何操作?为什么不将状态更改为STATE_WAITING_NON_PRECAPTURE?
The log keeps printing aeState = 2, which is CONTROL_AE_STATE_CONVERGED. My question is why the code does nothing when the AE is converged? Why not change state to STATE_WAITING_NON_PRECAPTURE?
我的意思是为什么不这样做呢?
I mean why not doing this instead?
case STATE_WAITING_PRECAPTURE: {
// CONTROL_AE_STATE can be null on some devices
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED ||
aeState == CaptureResult.CONTROL_AE_STATE_PRECAPTURE ||
aeState == CaptureRequest.CONTROL_AE_STATE_FLASH_REQUIRED) {
mState = STATE_WAITING_NON_PRECAPTURE;
}
else
{
Log.e(TAG,"aeState = " + aeState);
}
break;
}
ps:如果我想每2秒拍照一次,应该在哪里调用takePicture()?目前,我在CaptureCallback中调用了它,但是看起来有些竞争情况,因为CaptureCallback在后台线程中.
ps: Where should I call takePicture() if I want to take photo every 2 seconds? Currently I call it in the CaptureCallback, but look like there some race condition because the CaptureCallback is in the background thread.
谢谢.
推荐答案
代码应在此之前将AE_PRECAPTURE_TRIGGER设置为START;然后等待看到至少一个结果与AE_PRECAPTURE的AE_STATE一起出现,以了解触发器已激活并且预捕获已开始.然后它将等待第一个非PRECAPTURE AE_STATE知道预捕获已完成.
The code should be setting the AE_PRECAPTURE_TRIGGER to START right before this; it's then waiting to see at least one result come in with AE_STATE of AE_PRECAPTURE to know the trigger has activated and precapture has started. It'll then wait for the first non-PRECAPTURE AE_STATE to know that precapture has completed.
这篇关于用android Camera2连续拍摄静态照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!