问题描述
我想为自己开发一个Android Camera App(如果有兴趣的人可以共享),在录制视频时可以手动对焦.
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 .如果是这样,那么您可以通过设置自动对焦模式来控制镜头设置为OFF,然后设置镜头焦距为您想要的值.如果未列出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的手动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!