使用 android camera2 API 手动对焦 [英] Manual Focus using android camera2 API

查看:60
本文介绍了使用 android camera2 API 手动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为自己开发一个Android相机应用程序(如果有兴趣的人可以分享),在视频录制时具有手动对焦.

I want to develop an Android Camera App for myself (can share it if there are interested people) that has a manual focus while video recording.

我已将 SeekBar 添加到 google 示例 Camera2 应用,但我找不到实现手动对焦的方式.

I've added a SeekBar to the google sample Camera2 app but I can't find the way to implement the manual focus.

我找到了 camera2, android 中的手动对焦,但它不适用于我的 LG G4.股票相机应用几乎是完美的,因为它不允许在视频模式下手动对焦.

I found Manual focus in camera2, android but it doesn't work on my LG G4. The stock camera app is almost perfect since it doesn't allow the manual focus in video mode.

你们中有人有想法吗?

这是 SeekBar 侦听器的代码:

here's the code of the SeekBar listener:

@Override
public void onStopTrackingTouch(SeekBar seekBar) {}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
    mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_OFF);
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
    float minimumLens = characteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE);
    float num = (((float)progress) * minimumLens / 100);
    mPreviewBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, num);
}

推荐答案

您需要检查您正在运行的设备是否真的支持在 camera2 中手动控制.

You need to check if the device you're running on actually supports manual controls in camera2.

关键是可用功能相机设备列出MANUAL_SENSOR.如果是这样,那么您可以通过设置自动对焦模式 关闭,然后设置镜头焦距 到您想要的值.如果未列出 MANUAL_SENSOR,则该设备很可能不支持手动对焦控制(不幸的是,某些制造商为其默认相机应用使用专用接口来实现手动对焦控制).

The key is whether the available capabilities of the camera device lists MANUAL_SENSOR. If so, then you can control the lens by setting the autofocus mode to OFF, and then setting the lens focus distance to your desired value. If MANUAL_SENSOR is not listed, then the device very likely doesn't support manual focus control (Some manufacturers use private interfaces for their default camera app to implement manual focus control, unfortunately).

这些都应该包含在您用来控制预览的重复请求中.

These should all go into the repeating request you're using to control preview.

这篇关于使用 android camera2 API 手动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆