Beispiel #1
0
        /// <summary>
        /// A texture representing the confidence for each pixel in the raw depth for
        /// the current frame. See the <a href="https://developers.google.com/ar/eap/raw-depth">
        /// developer guide</a> for more information about raw depth.
        /// </summary>
        /// <param name="occlusionManager">The AROcclusionManager instance.</param>
        /// <returns>
        /// The environment raw depth confidence texture, if any. Otherwise, null.
        /// </returns>
        public static Texture2D GetEnvironmentRawDepthConfidenceTexture(
            this AROcclusionManager occlusionManager)
        {
            if (occlusionManager.currentEnvironmentDepthMode ==
                EnvironmentDepthMode.Disabled)
            {
                Debug.LogWarning(
                    "Environment raw depth confidence texture is not available" +
                    " when EnvironmentDepthMode is Disabled.");
                return(null);
            }

            if (!TryGetLastFrameFromExtensions(out XRCameraFrame frame))
            {
                return(null);
            }

            if (CachedData.TryGetCachedData(
                    CachedData.RawDepthConfidenceTexture, out Texture2D texture) &&
                CachedData.TryGetCachedData(
                    CachedData.RawDepthConfidenceTimestamp, out long timestamp) &&
                texture != null && timestamp == frame.timestampNs)
            {
                return(texture);
            }

            IntPtr imageHandle = FrameApi.AcquireRawDepthConfidenceImage(
                ARCoreExtensions._instance.currentARCoreSessionHandle,
                frame.FrameHandle());

            if (imageHandle == IntPtr.Zero)
            {
                return(null);
            }

            ImageApi.UpdateTexture(
                ARCoreExtensions._instance.currentARCoreSessionHandle, imageHandle,
                TextureFormat.Alpha8, ref texture);
            ImageApi.Release(imageHandle);
            CachedData.SetCachedData(CachedData.RawDepthConfidenceTexture, texture);
            CachedData.SetCachedData(CachedData.RawDepthConfidenceTimestamp, frame.timestampNs);

            return(texture);
        }
Beispiel #2
0
        /// <summary>
        /// Get the latest person mask texture that corresponds to the current frame in
        /// <a href="https://docs.unity3d.com/ScriptReference/TextureFormat.Alpha8.html">
        /// TextureFormat.Alpha8</a> format where each pixel represents the confidence of
        /// the segmentation result: 255 represents high confidence that the pixel is part of
        /// a person, 0 represents high confidence that the pixel is not part of a person.
        /// </summary>
        /// <param name="occlusionManager">The AROcclusionManager instance.</param>
        /// <returns>If available, the texture containing the person mask.
        /// Otherwise, returns null and logs the failure reason,
        /// e.g. Segmentation Mode is Disabled, or current camera configuration
        /// is incompatible with <c><see cref="SegmentationMode"/></c>.<c>People</c>.</returns>
        public static Texture2D GetPersonMaskTexture(this AROcclusionManager occlusionManager)
        {
            if (ARCoreExtensions._instance.ARCoreExtensionsConfig.SegmentationMode !=
                SegmentationMode.People)
            {
                Debug.LogWarning(
                    "Person mask texture is not available when SegmentationMode is not People.");
                return(null);
            }

            if (!TryGetLastFrameFromExtensions(out XRCameraFrame frame))
            {
                return(null);
            }

            if (CachedData.TryGetCachedData(
                    CachedData.PersonMaskTexture, out Texture2D texture) &&
                CachedData.TryGetCachedData(
                    CachedData.PersonMaskTextureTimestamp, out long timestamp) &&
                texture != null && timestamp == frame.timestampNs)
            {
                return(texture);
            }

            IntPtr sessionHandle = ARCoreExtensions._instance.currentARCoreSessionHandle;
            IntPtr imageHandle   = FrameApi.AcquirePersonMaskImage(
                sessionHandle, frame.FrameHandle());

            if (imageHandle != IntPtr.Zero)
            {
                ImageApi.UpdateTexture(
                    sessionHandle, imageHandle, TextureFormat.Alpha8, ref texture);
                ImageApi.Release(imageHandle);
                CachedData.SetCachedData(CachedData.PersonMaskTexture, texture);
                CachedData.SetCachedData(
                    CachedData.PersonMaskTextureTimestamp, frame.timestampNs);
            }

            return(texture);
        }