gpt4 book ai didi

Android Camera2 对焦状态卡住

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:04:24 25 4
gpt4 key购买 nike

我需要在我的应用程序中使用 Camera2 API。 (API21+)我找到了下一个示例: https://github.com/googlesamples/android-Camera2Basic

我下载了它并开始在我的手机上使用。当我按下“图片”按钮时,它调用了 takePhoto 方法。

private void takePicture() {
lockFocus();
}

它是一个状态机。有时这台机器卡在 STATE_WAITING_LOCK 上。我的设备正在等待 Focus,但没有任何反应! (是的,我的设备支持自动对焦)

case STATE_WAITING_LOCK: {
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
if (afState == null) {
captureStillPicture();
} else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
// 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) {
mState = STATE_PICTURE_TAKEN;
captureStillPicture();
} else {
runPrecaptureSequence();
}
}
break;
}

这个问题有什么好的解决方案?这个程序有时会在这里崩溃:

private void unlockFocus() {
try {
// Reset the auto-focus trigger
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
setAutoFlash(mPreviewRequestBuilder);
/*HERE*/ mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
// After this, the camera will go back to the normal state of preview.
mState = STATE_PREVIEW;
mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}

为什么我的设备无法对焦?

最佳答案

您的程序似乎有时会卡在 CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED 中,根据文档“AF 算法无法对焦。镜头没有移动。” link

尝试取消 AF_TRIGGER 并重新启动它。像这样:

 if (afState == CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED) {
getRidOfNotFocusedLock();
}

和:

private void getRidOfNotFocusedLock(){
try {
mPreviewRequestBuilder.set(
CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
mCaptureSession.capture(
captureRequestBuilder.build(), captureSessionCaptureCallback, backgroundHandler);
mPreviewRequestBuilder.set(
CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);

} catch (CameraAccessException e) {
e.printStackTrace();
}
}

关于Android Camera2 对焦状态卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44527420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com