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。 此外,请启用地理空间模式和街景几何图形以使用地理空间深度。
Java
Config config = session.getConfig(); // Check whether the user's device supports the Depth API. boolean isDepthSupported = session.isDepthModeSupported(Config.DepthMode.AUTOMATIC); boolean isGeospatialSupported = session.isGeospatialModeSupported(Config.GeospatialMode.ENABLED); if (isDepthSupported && isGeospatialSupported) { // These three settings are needed to use Geospatial Depth. config.setDepthMode(Config.DepthMode.AUTOMATIC); config.setGeospatialMode(Config.GeospatialMode.ENABLED); config.setStreetscapeGeometryMode(Config.StreetscapeGeometryMode.ENABLED); } session.configure(config);
Kotlin
val config = session.config // Check whether the user's device supports the Depth API. val isDepthSupported = session.isDepthModeSupported(Config.DepthMode.AUTOMATIC) val isGeospatialSupported = session.isGeospatialModeSupported(Config.GeospatialMode.ENABLED) if (isDepthSupported && isGeospatialSupported) { // These three settings are needed to use Geospatial Depth. config.depthMode = Config.DepthMode.AUTOMATIC config.geospatialMode = Config.GeospatialMode.ENABLED config.streetscapeGeometryMode = Config.StreetscapeGeometryMode.ENABLED } session.configure(config)
启用地理空间深度后,即可通过现有 API 调用来访问深度图像,如深度开发者指南中所述。
Java
// Retrieve the depth image for the current frame, if available. Image depthImage = null; try { depthImage = frame.acquireDepthImage16Bits(); // Use the depth image here. } catch (NotYetAvailableException e) { // This 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. } finally { if (depthImage != null) { depthImage.close(); } }
Kotlin
// Retrieve the depth image for the current frame, if available. try { frame.acquireDepthImage16Bits().use { depthImage -> // Use the depth image here. } } catch (e: NotYetAvailableException) { // This 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. }
后续步骤
- 了解如何在增强现实体验中使用街景几何图形。
- 通过学习“场景语义和地理空间深度”Codelab,了解如何构建使用地理空间深度的应用。