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

地理空間深度英雄

ARCore Depth API 現在支援地理空間深度,如果同時啟用街景服務幾何圖形,就會自動增加深度 API 的範圍和速度。在 VPS 涵蓋範圍啟用街景服務幾何圖形的情況下,輸出圖像會納入 Depth API 的輸出圖像,包括從目前位置擷取到 65 公尺內區域的地形和建築物幾何圖形。從幾何圖形擷取的深度資料會與局部深度觀察合併,並會隨著使用者移動到新位置而更新。

ARCore Depth API 呼叫現在會合併為單一深度圖片,提供相機的當地觀測,以及街景服務幾何圖形的建築物和地形。

裝置相容性

地理空間深度適用於所有支援深度 API 的裝置這項功能不必使用支援的硬體深度感應器,例如飛行時間 (ToF) 感應器。然而 Depth API 會使用裝置可能支援的任何硬體感應器。

效能影響

地理空間深度會在課程開始時,導入一次性的簡易計算作業,將街景服務幾何圖形整合到最初下載時的深度表示法,但不一定會增加深度運算成本。

深度範圍

在沒有地理空間深度的情況下,一般的深度圖片遠離 20-30 公尺,深度觀測資料的密度和準確性也會降低到上述範圍之外。啟用地理空間深度後,即使一開始只移動少量動作,密集取樣的深度值通常仍會達到 65.535 公尺上限。

用途

ARCore Depth API 可用於所有已支援的現有用途。透過地理空間深度功能,在 VPS 支援位置取得的深度圖片可以更快產生長遠深度,有助於在戶外環境中指定長範圍深度。以下列舉部分用途:

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

限制

地理空間深度僅適用於支援 VPS 本地化和街景服務幾何圖形的區域。在其他地區,ARCore Depth API 會在沒有地理空間值的情況下正常運作。

必要條件

請務必瞭解基本 AR 概念 以及如何在繼續操作前設定 ARCore 工作階段

啟用地理空間深度

新的 ARCore 工作階段中, 檢查使用者的裝置是否支援深度和 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.
}

後續步驟