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。此外,請啟用地理空間模式和街景幾何圖形,以便使用地理空間深度。
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; }
後續步驟
- 瞭解如何在擴增實境體驗中使用街景幾何圖形。