gpt4 book ai didi

android - 如何在 Android CameraX 中使用手动对焦?

转载 作者:行者123 更新时间:2023-11-30 04:56:03 45 4
gpt4 key购买 nike

我正在尝试像在 Camera2 API 中一样对 CameraX 进行手动对焦

在 Camera2 API 中我使用以下代码

final CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); 

captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);

captureBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, mLensFocusDistance);

android camera X 可以手动对焦吗?如果是怎么办

提前致谢

最佳答案

有一种方法可以通过使用 Camera2Interop.Extender 访问低级 camera2 API 在 cameraX 中使用手动对焦.您应该像这样设置两个额外的选项来预览构建器:

void setFocusDistance(ExtendableBuilder<?> builder, float distance) {
Camera2Interop.Extender extender = new Camera2Interop.Extender(builder);
extender.setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_OFF);
extender.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, distance);
}

并在构建您的 cameraX 预览请求时使用它:

float focusDistance = 0F; // example: infinite focus
Preview.Builder previewBuilder = new Preview.Builder();
setFocusDistance(previewBuilder, focusDistance);
preview = previewBuilder.build();
preview.setSurfaceProvider(viewFinder.getSurfaceProvider());

请注意,您还可以通过这种方式设置其他 camera2 CaptureRequest 选项。


以下是查找 LENS_INFO_MINIMUM_FOCUS_DISTANCE(通常约为 10f 的值)的方法:

theCamera = cameraProvider.bindToLifecycle(...
CameraCharacteristics camChars = Camera2CameraInfo
.extractCameraCharacteristics(theCamera.getCameraInfo());
float discoveredMinFocusDistance = camChars
.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
Log.i("dev", "found it! " + discoveredMinFocusDistance);

关于android - 如何在 Android CameraX 中使用手动对焦?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59136897/

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