在Camera2 API实现点击聚焦
问题说明
我想在我的自定义相机中实现点击聚焦功能. 这是Google https://github.com/谷歌samples/android-Camera2Basic 提供的基本代码.
i want to implement tap to focus feature in my custom camera. This is the basic code provided by Google https://github.com/谷歌samples/android-Camera2Basic
这是我认为应该添加功能的代码段 如果有人实现了Camera2 API,请提供帮助!
Here's the code snippet where i think i should add my feature If anyone has implemented the Camera2 API please help!
private void lockFocus() {
try {
// This is how to tell the camera to lock focus.
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
CameraMetadata.CONTROL_AF_TRIGGER_START);
// Tell #mCaptureCallback to wait for the lock.
mState = STATE_WAITING_LOCK;
mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
正确答案
您需要将自动对焦和自动曝光区域设置为用户点击的区域.
You'll need to set the autofocus and auto-exposure region to the area tapped by the user.
键是 CONTROL_AF_REGIONS 和CONTROL_AE_REGIONS .
它们的单位位于传感器活动数组坐标系中,因此您必须将UI触摸坐标转换为相对于预览视图的坐标,然后再转换为活动数组坐标.
The units for them are in the sensor active array coordinate system, so you'll have to translate from your UI touch coordinates to coordinates relative to your preview view, and from there, to the active array coordinates.
如果预览的长宽比与传感器的长宽比匹配,则很简单;如果不是,则必须针对创建预览输出所做的裁剪进行调整.目前,此处是最好的裁剪方法.请注意,如果您还要应用缩放,则还需要在计算中包括缩放因子.
If the aspect ratio of your preview matches that of the sensor, then that's straightforward; if not, you'll have to adjust for the crop that is done to create the preview output. The best diagram for how the cropping works is currently here. Note that if you're also applying zoom, you'll want to include the zoom factor as well in your calculations.
计算完区域后,您可能需要将AF模式设置为AUTO(而不是通常用于常规预览的CONTINUOUS_PICTURE),然后触发AF.收敛AF后(查看捕获结果中的AF状态,等待AF_STATE_FOCUSED_LOCKED),可以拍摄清晰的照片.如果您想在一段时间后返回到正常操作状态,或者用户取消对焦点的触摸,请将AF模式切换回CONTINUOUS_PICTURE.
Once you've calculated the region, you'll probably want to set the AF mode to AUTO (instead of CONTINUOUS_PICTURE which is usually used for normal preview), and then trigger AF. Once you converge AF (look at the AF state in the capture results, wait for AF_STATE_FOCUSED_LOCKED), you're good to take a picture that's in focus. If you want to return to normal operation after some time or the user cancels the touch to focus, switch AF mode back to CONTINUOUS_PICTURE.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcecbke
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20 -
复制文件夹/文件而不修改属性?
it1352 07-15