利用地理空間深度擴大範圍

地理空間深度圖

ARCore Depth API 現在支援地理空間深度,因此在啟用街景幾何圖形時,系統會自動增加 Depth API 的範圍和速度。如果所在地區已啟用 VPS 涵蓋範圍並啟用街景服務幾何圖形,則 Depth API 的輸出圖像會包含從目前位置擷取到該區域的地形和建築物幾何圖形。從幾何圖形擷取的深度資料會與本機深度觀察合併,並在使用者移至新位置時更新。

ARCore 深度 API 呼叫現在提供相機以及 Streetscape Geometry 的建築物和地形資料,現在可以合併為單一深度圖片。

裝置相容性

支援 Depth API 的裝置都能提供地理空間深度資料。這項功能不需要支援的硬體深度感應器,例如飛行時間 (ToF) 感應器。不過,Depth API 使用裝置所有支援的硬體感應器。

效能影響

地理空間深度在工作階段開始時導入了小型的一次性計算,可在最初下載時將 Streetscape 幾何圖形整合到深度呈現,但並不會大幅增加深度運算成本。

深度範圍

在沒有地理空間深度的情況下,一般情況下,深度圖片的範圍在 20 到 30 公尺內,而且深度觀察的密度和精確度也會降低。啟用「地理空間深度」功能後,即使只有少量初期的移動,依一般而言,密集取樣的深度值仍將達到最大值 65.535 公尺。

應用情境

所有目前支援的用途都能使用 ARCore Depth API。透過地理空間深度功能,從 VPS 支援位置取得的深度圖片,就會更快填入長範圍深度,可以幫助在戶外環境中指定長距離的深度。以下列舉部分用途:

  • 大規模遮蔽虛擬內容和其他視覺效果
  • 戶外導覽
  • 測量距離

限制

只有支援 VPS 本地化和街景幾何圖形的區域才支援地理空間深度。在其他地區,ARCore 深度 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.
}

後續步驟