问题
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.
I have couple of questions:
Do I need to implement some checking in a method inside CameraCaptureSession.CaptureCallback
?
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.
回答1:
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.
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.
I'd also recommend the CONTINUOUS_PICTURE focus mode instead of AUTO; it's likely to get you a focused image faster.
来源:https://stackoverflow.com/questions/46823116/android-camera2-auto-focus-and-exposure