Android Camera2:自动对焦和曝光 [英] Android Camera2: Auto Focus and Exposure

查看:1702
本文介绍了Android Camera2:自动对焦和曝光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android相机应用程序中,我正在使用Camera2 API.该应用程序不显示Camera的预览,而我已经以某种方式实现了它,当按下UI上的按钮时,它将拍摄图像.但是问题在于自动对焦和自动曝光.简而言之,我需要使摄影机始终聚焦在其视图的中间.因此,在构建请求时,我添加了以下属性:

In my Android camera application I'm using the Camera2 API. The application doesn't show the preview of the Camera, and I've implemented it in a way, when a button on the UI is pressed, it takes an image. But the problem is with auto focus and auto exposure. Simply, I need to camera always focused on the middle of its view. So when building the request, I added following properties:

captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
captureBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_AUTO);
captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
captureBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);  

但是问题仍然在于图像没有聚焦.

But the problem is still the images are not focused.

我有几个问题:

我是否需要在CameraCaptureSession.CaptureCallback内部的方法中实现一些检查?

Do I need to implement some checking in a method inside CameraCaptureSession.CaptureCallback?

我还注意到,在ImageReader.OnImageAvailableListener中调用onImageAvailable时,不会触发CameraCaptureSession.CaptureCallbackonCaptureProgressed方法.

I also noticed that by the time onImageAvailable is called in ImageReader.OnImageAvailableListener, the onCaptureProgressed method of CameraCaptureSession.CaptureCallback is not triggered.

我在这里缺少什么要点?我是否需要实现一个线程来等待相机对焦,这将在按下拍照"按钮时开始.

What are the points I'm missing here? Do I need to implement a thread to wait until the camera is focused, which will start by when pressing the take picture button.

请注意,此应用程序没有相机预览.

Please note that there's no camera preview for this application.

推荐答案

您是否仅发送单个捕获请求?还是在后台运行重复请求,然后仅在按下按钮时发出高分辨率捕获?

Are you sending only a single capture request? Or are you running a repeating request in the background, and then only issuing a high-resolution capture on button press?

前者将无法真正起作用-您必须要有大量的请求才能使自动曝光,对焦和白平衡算法收敛到良好的值.单次拍摄将无法正确测光或聚焦.

The former won't really work - you have to have a flow of requests to have the autoexposure, focus, and white balance algorithms converge to good values. A single capture won't be properly metered or focused.

请查看 Camera2Basic 示例;如果仅用SurfaceTexture替换该示例中的TextureView(给它一个随机的纹理ID,并且不调用updateTexImage),那么您将无法预览.但是它可以正确实现聚焦和预捕获触发,这对您在这里至关重要.首先,必须仅在一个请求上设置触发器,然后您确实需要观看捕获结果,以查看曝光/焦点状态何时变为FOCUSED或CONVERGED.

Please take a look at the Camera2Basic sample; if you replace the TextureView in that sample with just a SurfaceTexture (give it a random texture ID and don't call updateTexImage), then you can have no preview. But it implements focusing and the precapture trigger correctly, which is critical for you here. For one, the triggers must only be set on one request, and then you do need to watch the capture results coming back to see when the exposure / focus state changes to FOCUSED or CONVERGED.

我还建议您使用CONTINUOUS_PICTURE对焦模式,而不要使用AUTO;可能会更快地为您提供聚焦的图像.

I'd also recommend the CONTINUOUS_PICTURE focus mode instead of AUTO; it's likely to get you a focused image faster.

这篇关于Android Camera2:自动对焦和曝光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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