• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在Camera2 API实现点击聚焦

用户头像
it1352
帮助1

问题说明

我想在我的自定义相机中实现点击聚焦功能. 这是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();
    }
}

正确答案

#1

您需要将自动对焦和自动曝光区域设置为用户点击的区域.

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
系列文章
更多 icon
同类精品
更多 icon
继续加载