AR Foundation Android アプリで Raw Depth を使用する
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Raw Depth API は、Full Depth API データよりも精度の高いカメラ画像の深度データを提供しますが、必ずしもすべてのピクセルをカバーするとは限りません。未加工の深度画像と、それに対応する信頼性画像は、さらに処理することもできます。これにより、アプリは個々のユースケースに十分な精度を持つ深度データのみを使用できます。
デバイスの互換性
元の深度は、Depth API をサポートするデバイスで利用できます。Raw Depth API は、完全な Depth API と同様に、Time of Flight(ToF)センサーなどのサポートされているハードウェア深度センサーを必要としません。ただし、Raw Depth API とフル Depth API の両方で、デバイスに搭載されているサポートされているハードウェア センサーが使用されます。
Raw Depth API とフル Depth API
Raw Depth API は、より正確な深度推定を提供しますが、RAW 深度画像には、カメラ画像のすべてのピクセルの深度推定が含まれていない場合があります。一方、フル Depth API はピクセルごとに推定深度を提供しますが、深度の推定値がスムージングと補間処理を受けるため、ピクセル単位の深度データの精度が低下する可能性があります。深度画像の形式とサイズは、どちらの API でも同じです。コンテンツのみが異なります。
次の表は、キッチンの椅子とテーブルの画像を使用して、Raw Depth API とフル Depth API の違いを示しています。
API |
戻り値 |
カメラ画像 |
奥行き画像 |
信頼性の画像 |
Raw Depth API
|
- カメラ画像の一部(ただしすべてのピクセルではない)の非常に正確な深度推定値を含む未処理の深度画像。
- 未加工の深度画像の各ピクセルの信頼度を示す信頼度画像。奥行きの推定値がないカメラ画像ピクセルの信頼度はゼロです。
|
|
|
|
Full Depth API
|
- 各ピクセルの深度推定値を含む単一の「スムーズ化」された深度画像。
- この API には信頼性の高い画像は提供されていません。
|
|
|
該当なし
|
信頼性の画像
Raw Depth API から返される信頼画像では、明るいピクセルほど信頼値が高くなります。白色のピクセルは完全に信頼できるピクセル、黒色のピクセルは信頼できないピクセルを表します。一般に、カメラ画像内のテクスチャが多い領域(木など)では、テクスチャが少ない領域(壁など)よりも、未加工の深度信頼性が高くなります。テクスチャのないサーフェスは通常、信頼度がゼロになります。
対象デバイスにサポートされているハードウェア デプス センサーが搭載されている場合、テクスチャのないサーフェスでも、カメラに近い画像領域の信頼性が高くなります。
コンピューティングの費用
Raw Depth API のコンピューティング コストは、フル Depth API のコンピューティング コストの約半分です。
ユースケース
Raw Depth API を使用すると、シーン内のオブジェクトのジオメトリをより詳細に表す深度画像を取得できます。元の奥行きデータは、ジオメトリの理解タスクで奥行きの精度と詳細を高める必要がある AR エクスペリエンスを作成する場合に役立ちます。ユースケースには、次のようなものがあります。
前提条件
続行する前に、基本的な AR コンセプトと ARCore セッションを構成する方法を理解してください。
深度を有効にする
新しい ARCore セッションで、お客様のデバイスが Depth に対応しているかどうかを確認します。処理能力の制約により、ARCore 対応デバイスでも Depth API をサポートしていない場合があります。リソースを節約するため、ARCore ではデフォルトで深度が無効になっています。デプス モードを有効にして、アプリで Depth API を使用します。
var occlusionManager = // Typically acquired from the Camera game object.
// Check whether the user's device supports the Depth API.
if (occlusionManager.descriptor?.supportsEnvironmentDepthImage)
{
// If depth mode is available on the user's device, perform
// the steps you want here.
}
最新の未加工の深度画像を取得する
AROcclusionManager.TryAcquireEnvironmentDepthCpuImage()
を呼び出し、AROcclusionManager.environmentDepthTemporalSmoothingRequested
を使用して CPU で最新の未加工の深度画像を取得します。
最新の未加工の深度信頼度画像を取得する
AROcclusionManager.TryAcquireEnvironmentDepthConfidenceCpuImage()
を呼び出し、AROcclusionManager.environmentDepthTemporalSmoothingRequested
を使用して CPU で信頼度画像を取得します。
// Attempt to get the latest environment depth image.
if (occlusionManager && occlusionManager.TryAcquireEnvironmentDepthConfidenceCpuImage(out XRCpuImage image))
{
using (image)
{
UpdateRawImage(m_RawEnvironmentDepthConfidenceImage, image);
}
}
else
{
m_RawEnvironmentDepthConfidenceImage.enabled = false;
}
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-26 UTC。
[null,null,["最終更新日 2025-07-26 UTC。"],[[["\u003cp\u003eThe Raw Depth API delivers higher accuracy depth data compared to the full Depth API, but may not cover every pixel in the camera image.\u003c/p\u003e\n"],["\u003cp\u003eRaw depth images come with corresponding confidence images, allowing developers to filter data based on accuracy for specific use cases.\u003c/p\u003e\n"],["\u003cp\u003eConfidence images use lighter pixels to indicate higher confidence levels, with white representing full confidence and black representing no confidence.\u003c/p\u003e\n"],["\u003cp\u003eWhile requiring less computational power than the full Depth API, the Raw Depth API is ideal for applications like 3D reconstruction, measurement, and shape detection that need precise depth information.\u003c/p\u003e\n"],["\u003cp\u003eThis API is supported by all devices compatible with the Depth API and leverages any available hardware depth sensors for enhanced performance.\u003c/p\u003e\n"]]],["The Raw Depth API provides highly accurate depth data for some pixels in a camera image, unlike the full Depth API, which estimates depth for all pixels with less accuracy. The Raw Depth API also returns a confidence image, indicating the accuracy of each pixel's depth. Both APIs use the same image format and size. Raw Depth is computationally less expensive, and is suitable for applications like 3D reconstruction and measurement, but must be enabled in the ARCore session after checking device compatibility, and can be acquired via `AROcclusionManager.TryAcquireEnvironmentDepthCpuImage()` and `AROcclusionManager.TryAcquireEnvironmentDepthConfidenceCpuImage()`\n"],null,["# Use Raw Depth in your AR Foundation Android app\n\nThe Raw Depth API provides depth data for a camera image that has higher accuracy than full Depth API data, but does not always cover every pixel. Raw depth images, along with their matching confidence images, can also be further processed, allowing apps to use only the depth data that has sufficient accuracy for their individual use case.\n\nDevice compatibility\n--------------------\n\nRaw Depth is available on all [devices that support the Depth API](/ar/devices). **The Raw Depth API, like the full Depth API, does not require a supported hardware depth sensor, such as a time-of-flight (ToF) sensor.** However, both the Raw Depth API and the full Depth API make use of any supported hardware sensors that a device may have.\n\nRaw Depth API vs full Depth API\n-------------------------------\n\nThe Raw Depth API provides depth estimates with higher accuracy, but raw depth images may not include depth estimates for all pixels in the camera image. In contrast, the full Depth API provides estimated depth for every pixel, but per-pixel depth data may be less accurate due to smoothing and interpolation of depth estimates. **The format and size of depth images are the same across both APIs.** Only the content differs.\n\nThe following table illustrates the differences between the Raw Depth API and the full Depth API using an image of a chair and a table in a kitchen.\n\n| API | Returns | Camera image | Depth image | Confidence image |\n|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------|-------------|------------------|\n| Raw Depth API | - A raw depth image that contains a very accurate depth estimate for some, but not all, pixels in the camera image. - A confidence image that gives the confidence for every raw depth image pixel. Camera image pixels that do not have a depth estimate have a confidence of zero. | | | |\n| Full Depth API | - A single \"smoothed\" depth image that contains a depth estimate for every pixel. - No confidence image is provided with this API. | | | N/A |\n\n### Confidence images\n\nIn confidence images returned by the Raw Depth API, lighter pixels have higher confidence values, with white pixels representing full confidence and black pixels representing no confidence. In general, regions in the camera image that have more texture, such as a tree, will have higher raw depth confidence than regions that don't, such as a blank wall. Surfaces with no texture usually yield a confidence of zero.\n\nIf the target device has a supported hardware depth sensor, confidence in areas of the image close enough to the camera will likely be higher, even on textureless surfaces.\n\n### Compute cost\n\nThe compute cost of the Raw Depth API is about half of the compute cost for the full Depth API.\n\nUse cases\n---------\n\nWith the Raw Depth API, you can obtain depth images that provide a more detailed representation of the geometry of the objects in the scene. Raw depth data can be useful when creating AR experiences where increased depth accuracy and detail are needed for geometry-understanding tasks. Some use cases include:\n\n- 3D reconstruction\n- Measurement\n- Shape detection\n\nPrerequisites\n-------------\n\nMake sure that you understand [fundamental AR concepts](/ar/develop/fundamentals)\nand how to [configure an ARCore session](/ar/develop/unity-arf/session-config) before proceeding.\n\nEnable Depth\n------------\n\nIn a [new ARCore session](/ar/develop/unity-arf/session-config), check whether a user's device supports Depth. Not all ARCore-compatible devices support the Depth API due to processing power constraints. To save resources, depth is disabled by default on ARCore. Enable depth mode to have your app use the Depth API. \n\n var occlusionManager = // Typically acquired from the Camera game object.\n\n // Check whether the user's device supports the Depth API.\n if (occlusionManager.descriptor?.supportsEnvironmentDepthImage)\n {\n // If depth mode is available on the user's device, perform\n // the steps you want here.\n }\n\nAcquire the latest raw depth image\n----------------------------------\n\nCall [`AROcclusionManager.TryAcquireEnvironmentDepthCpuImage()`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api//UnityEngine.XR.ARFoundation.AROcclusionManager.html#UnityEngine_XR_ARFoundation_AROcclusionManager_TryAcquireEnvironmentDepthCpuImage_UnityEngine_XR_ARSubsystems_XRCpuImage__) and use [`AROcclusionManager.environmentDepthTemporalSmoothingRequested`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api//UnityEngine.XR.ARFoundation.AROcclusionManager.html#UnityEngine_XR_ARFoundation_AROcclusionManager_environmentDepthTemporalSmoothingRequested) to acquire the latest raw depth image on the CPU.\n\nAcquire the latest raw depth confidence image\n---------------------------------------------\n\nCall [`AROcclusionManager.TryAcquireEnvironmentDepthConfidenceCpuImage()`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api//UnityEngine.XR.ARFoundation.AROcclusionManager.html#UnityEngine_XR_ARFoundation_AROcclusionManager_TryAcquireEnvironmentDepthConfidenceCpuImage_UnityEngine_XR_ARSubsystems_XRCpuImage__) and use [`AROcclusionManager.environmentDepthTemporalSmoothingRequested`](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.2/api//UnityEngine.XR.ARFoundation.AROcclusionManager.html#UnityEngine_XR_ARFoundation_AROcclusionManager_environmentDepthTemporalSmoothingRequested) to acquire the confidence image on the CPU. \n\n // Attempt to get the latest environment depth image.\n if (occlusionManager && occlusionManager.TryAcquireEnvironmentDepthConfidenceCpuImage(out XRCpuImage image))\n {\n using (image)\n {\n UpdateRawImage(m_RawEnvironmentDepthConfidenceImage, image);\n }\n }\n else\n {\n m_RawEnvironmentDepthConfidenceImage.enabled = false;\n }"]]