Exemplo n.º 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);
        }