gpt4 book ai didi

java - 如何手动控制Camera2手动对焦?

转载 作者:行者123 更新时间:2023-12-02 04:53:28 25 4
gpt4 key购买 nike

问题

我的手机支持所有手动配置。使用( https://github.com/pinguo-yuyidong/Camera2 )进行测试,允许我们使用搜索栏进行调整。

我想在开始预览时设置镜头焦距的固定值,直到关闭应用程序为止。

将自动对焦模式设置为关闭并设置镜头焦距后。预览没有显示任何效果,但 Focus 2 值发生了变化。

如何克服这个问题?

示例代码(Java)

    private CaptureRequest mPreviewRequest;
private void startCameraPreview() throws CameraAccessException {
SurfaceTexture texture = textureview.getSurfaceTexture();
texture.setDefaultBufferSize(imageDimensions.getWidth(), imageDimensions.getHeight());
Surface surface = new Surface(texture);
mPreviewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
mPreviewRequestBuilder.addTarget(surface);
System.out.println("Focus 1 ====== "+mPreviewRequestBuilder.get(CaptureRequest.LENS_FOCUS_DISTANCE));
cameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
if (cameraDevice == null) {
return;
}
cameraSession = session;

try {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_OFF);
mPreviewRequestBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, 7.5f);
mPreviewRequest = mPreviewRequestBuilder.build();
cameraSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, backgroundHandler);
System.out.println("Focus 2 ====== "+mPreviewRequestBuilder.get(CaptureRequest.LENS_FOCUS_DISTANCE));
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession session) {
Toast.makeText(getApplicationContext(),"Failed",Toast.LENGTH_SHORT).show();
}
}, null);
}

private static final int STATE_PREVIEW = 0;
private int mState = STATE_PREVIEW;
private CameraCaptureSession.CaptureCallback mCaptureCallback = new CameraCaptureSession.CaptureCallback() {
private void process(CaptureResult result){
switch(mState){
case STATE_PREVIEW:{
break;
}
}
}
};

输出

焦点 1 ====== 0.0

焦点 2 ====== 7.5

更改值时我看不到差异。

最佳答案

找到答案

不知道为什么我需要 mPreviewRequest 和 setRepeatingRequest 2 次,但它有效。

mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_OFF);
mPreviewRequest = mPreviewRequestBuilder.build();
cameraSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, backgroundHandler);
mPreviewRequestBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, 7.5f);
mPreviewRequest = mPreviewRequestBuilder.build();
cameraSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, backgroundHandler);

关于java - 如何手动控制Camera2手动对焦?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56421471/

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