Example #1
0
        /// <summary>
        /// Attempt to get the latest person mask data that corresponds to the current frame
        /// for CPU access. 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. If the data is available,
        /// it is copied into the output image buffer.
        /// </summary>
        /// <param name="occlusionManager">The AROcclusionManager instance.</param>
        /// <param name="outputBuffer">
        /// The output image buffer to be filled with raw image data.</param>
        /// <returns>If available, returns a Vector2Int which represents the size of the image.
        /// Otherwise, returns <c>Vector2Int.zero</c> and logs the failure reason, e.g.
        /// Segmentation Mode is Disabled, or current camera configuration s incompatible with
        /// <c><see cref="SegmentationMode"/></c>.<c>People</c>.</returns>
        public static Vector2Int TryAcquirePersonMaskRawData(
            this AROcclusionManager occlusionManager, ref byte[] outputBuffer)
        {
            if (ARCoreExtensions._instance.ARCoreExtensionsConfig.SegmentationMode !=
                SegmentationMode.People)
            {
                Debug.LogWarning(
                    "Person mask data is not available when SegmentationMode is not People.");
                return(Vector2Int.zero);
            }

            if (!TryGetLastFrameFromExtensions(out XRCameraFrame frame))
            {
                return(Vector2Int.zero);
            }

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

            if (imageHandle != IntPtr.Zero)
            {
                imageSize = ImageApi.UpdateRawData(
                    sessionHandle, imageHandle, ref outputBuffer);
                ImageApi.Release(imageHandle);
            }

            return(imageSize);
        }
Example #2
0
    private void Start()
    {
        _occlusionManager = FindObjectOfType <AROcclusionManager>();
        Debug.Assert(_occlusionManager);

        StartCoroutine(CheckDepthCoroutine());
    }
Example #3
0
 void OnValidate()
 {
     if (occlusionManager == null)
     {
         occlusionManager = FindObjectOfType <AROcclusionManager>();
     }
 }
Example #4
0
    void Awake()
    {
        if (Instance == null)
        {
            Instance = this;
        }

        arOcclusionManager = GetComponent <AROcclusionManager>();
    }
    private void Start()
    {
        _meshCollider = GetComponent <MeshCollider>();
        GetComponent <MeshRenderer>().enabled = Render;

        _occlusionManager = FindObjectOfType <AROcclusionManager>();
        Debug.Assert(_occlusionManager);

        ARSession.stateChanged += OnSessionStateChanged;
    }
Example #6
0
    private void Start()
    {
        _occlusionManager = FindObjectOfType <AROcclusionManager>();
        Debug.Assert(_occlusionManager);

        _cameraManager = FindObjectOfType <ARCameraManager>();
        Debug.Assert(_cameraManager);

        _cameraManager.frameReceived += OnCameraFrameReceived;

        // Assign the texture to the material.
        _material = GetComponent <Renderer>().sharedMaterial;
    }
Example #7
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);
        }
Example #8
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);
        }
Example #9
0
 void Awake()
 {
     _AROcclusionManager = GetComponent <AROcclusionManager>();
 }