ARCore Depth API 现在支持 Geospatial Depth,它会在同时启用 Streetscape Geometry 时自动增加 Depth API 的范围和速度。在启用了 VPS 覆盖范围和 Streetscape Geometry 的位置上,Depth API 的输出图像包含从当前位置(最远 65 米处)检索到的地形和建筑物几何图形。从几何图形中检索到的深度数据会与局部深度观测合并,并在用户移动到新位置时更新。
ARCore Depth API 调用现在可提供来自摄像头的本地观察结果以及来自 Streetscape Geometry 的建筑物和地形,并合并到一个深度图像中。
设备兼容性
所有支持 Depth API 的设备都支持地理空间深度。此功能不需要支持的硬件深度传感器,例如飞行时间 (ToF) 传感器。不过,Depth API 会使用设备可能具有的任何受支持的硬件传感器。
性能影响
Geospatial Depth 在会话开始时引入一个小小的一次性计算,以便在最初下载时将 Streetscape Geometry 集成到深度表示中,但除此之外不会明显增加深度计算成本。
深度范围
如果没有地理空间深度,一般的深度图像范围在大约 20-30 米之外,而深度观测的密度和准确性会降低到该范围之外。启用地理空间深度后,即使初始移动少量,密集采样深度值通常也会达到 65.535 米的最大值。
用例
ARCore Depth API 可用于已支持的所有现有用例。利用地理空间深度,在支持 VPS 的位置获取深度图像将比之前更快地填充长距离深度,从而支持针对户外环境中远距离深度的应用场景。一些使用场景包括:
- 建筑物大规模遮挡虚拟内容和其他视觉效果
- 户外导航
- 距离测量
限制
只有支持 VPS 定位和街景几何图形的区域才支持地理空间深度。在其他区域,ARCore Depth API 将在没有地理空间值的情况下正常运行。
前提条件
确保您了解基本 AR 概念以及如何配置 ARCore 会话,然后再继续。
启用地理空间深度
在新的 ARCore 会话中,检查用户的设备是否支持 Depth 和 Geospatial API。由于处理能力限制,并非所有与 ARCore 兼容的设备都支持 Depth API。
为节省资源,ARCore 上默认停用深度。启用深度模式,以便您的应用使用 Depth API。 此外,请启用地理空间模式和街景几何图形以使用地理空间深度。
int32_t is_depth_supported = 0; int32_t is_geospatial_supported = 0; // Check whether the user's device supports the Depth API. ArSession_isDepthModeSupported(ar_session, AR_DEPTH_MODE_AUTOMATIC, &is_depth_supported); ArSession_isGeospatialModeSupported(ar_session, AR_GEOSPATIAL_MODE_ENABLED, &is_geospatial_supported); ArConfig* ar_config = NULL; ArConfig_create(ar_session, &ar_config); if (is_depth_supported && is_geospatial_supported) { // These three settings are needed to use Geospatial Depth. ArConfig_setDepthMode(ar_session, ar_config, AR_DEPTH_MODE_AUTOMATIC); ArConfig_setGeospatialMode(ar_session, ar_config, AR_GEOSPATIAL_MODE_ENABLED); ArConfig_setStreetscapeGeometryMode(ar_session, ar_config, AR_STREETSCAPE_GEOMETRY_MODE_ENABLED); } CHECK(ArSession_configure(ar_session, ar_config) == AR_SUCCESS); ArConfig_destroy(ar_config);
启用地理空间深度后,即可通过现有 API 调用来访问深度图像,如深度开发者指南中所述。
// Retrieve the depth image for the current frame, if available. ArImage* depth_image = NULL; // If a depth image is available, use it here. if (ArFrame_acquireDepthImage16Bits(ar_session, ar_frame, &depth_image) != AR_SUCCESS) { // No depth image received for this frame. // This normally means that depth data is not available yet. // Depth data will not be available if there are no tracked // feature points. This can happen when there is no motion, or when the // camera loses its ability to track objects in the surrounding // environment. return; }
后续步骤
- 了解如何在增强现实体验中使用街景几何图形。