自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
相机焦外成像
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
摄像头焦外成像是一种浅景深效果,可通过以下方式实现:对一个场景中的多个部分进行模糊处理,以使这些部分不处于聚焦状态。在移动设备的摄像头上,可使用从两个摄像头的立体视觉或单摄像头的双光电二极管 (PD) 获取的深度信息实现焦外成像。
从 Android 11 开始,Android 平台支持焦外成像实现,并提供 API 以使该功能可供第三方应用使用。
实现
如需启用您设备上的摄像头焦外成像功能,请执行以下操作:
播发 ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES
:
此标记采用三整数元组数组的格式,每个元组的格式为 {mode, maxWidth, maxHeight}
。除 {ANDROID_CONTROL_EXTENDED_SCENE_MODE_DISABLED, 0, 0}
外,摄像头 HAL 还必须列出 ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_STILL_CAPTURE
和/或 ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_CONTINUOUS
模式及其相应的最大流式传输大小。
播发 ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_ZOOM_RATIO_RANGES
:
此标记采用 {minZoomRatio, maxZoomRatio}
数组的格式,该数组包含已启用扩展取景模式的所有缩放比例范围,顺序与 ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES
相同。[1.0, 1.0]
缩放范围表示不支持缩放。
在 ANDROID_CONTROL_AVAILABLE_MODES
中填充 ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE
。
如需触发焦外成像功能,应用必须将 ANDROID_CONTROL_MODE
设置为 ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE
,并将 ANDROID_CONTROL_EXTENDED_SCENE_MODE
设置为受支持的扩展取景模式中的一种。请注意,由于立体视觉计算,实现焦外成像可能会消耗额外的内存。
如果受支持的扩展取景模式无法按帧应用,并且会导致在启用/停用时出现意外延迟,请在 ANDROID_REQUEST_AVAILABLE_SESSION_KEYS
中添加 ANDROID_CONTROL_EXTENDED_SCENE_MODE
。同时,实现 ICameraDeviceSession::isReconfigurationRequired()
方法以避免针对不需要重新配置的扩展取景模式重新配置。
验证
如需验证设备上的焦外成像功能,请运行以下 CTS、VTS 和 CTS 验证程序测试:
CtsCameraTestCases
VtsHalCameraProviderV2_4TargetTest
- CTS 验证程序中的
CameraBokehTest
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Camera bokeh is a shallow depth-of-field effect created by blurring out parts of\na scene so that they're not in focus. On cameras on mobile devices, bokeh is\nachieved using depth information acquired from the stereo vision from two\ncameras or from dual photodiodes (PDs) of a single camera.\n\nStarting from Android 11, the Android platform\nsupports bokeh implementations and provides APIs to make the feature available\nto third-party apps.\n\nImplementation\n--------------\n\nTo make the camera bokeh feature available on your device, do the following:\n\n- Advertise `ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES`:\n\n This tag is in the format of a three-integer tuple array, with each tuple\n in the format of `{mode, maxWidth, maxHeight}`. In addition to\n `{ANDROID_CONTROL_EXTENDED_SCENE_MODE_DISABLED, 0, 0}`, the camera HAL must\n also list one or both of the\n `ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_STILL_CAPTURE` and\n `ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_CONTINUOUS` modes with their\n corresponding maximum streaming sizes.\n- Advertise\n `ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_ZOOM_RATIO_RANGES`:\n\n This tag is in the format of a `{minZoomRatio, maxZoomRatio}` array,\n which contains all the zoom ratio ranges for an enabled extended scene\n mode, in the same order as in\n `ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES`. A zoom range of\n `[1.0, 1.0]` means that zoom isn't supported.\n- Populate `ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE` in\n `ANDROID_CONTROL_AVAILABLE_MODES`.\n\nFor an app to trigger the bokeh feature, the app must set `ANDROID_CONTROL_MODE`\nto `ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE` and\n`ANDROID_CONTROL_EXTENDED_SCENE_MODE` to one of supported extended scene modes.\nNote that implementing bokeh might lead to extra memory consumption because of\nstereo computation.\n\nIf a supported extended scene mode can't be applied per frame and results in\nunexpected delays when enabled/disabled, include\n`ANDROID_CONTROL_EXTENDED_SCENE_MODE` in\n`ANDROID_REQUEST_AVAILABLE_SESSION_KEYS`. At the same time, implement the\n`ICameraDeviceSession::isReconfigurationRequired()` method to avoid\nreconfiguration for extended scene modes that don't require reconfiguration.\n\nValidation\n----------\n\nTo validate the bokeh feature on your device, run the following CTS, VTS, and\nCTS Verifier tests:\n\n- `CtsCameraTestCases`\n- `VtsHalCameraProviderV2_4TargetTest`\n- `CameraBokehTest` in CTS Verifier"]]