Ejemplo n.º 1
0
 public void RenderOutput(WebCamScreenController screenController, string input)
 {
     if (outputStreamPoller.Next(outputPacket))
     {
         Debug.Log($"{outputPacket.GetValue()}");
     }
 }
Ejemplo n.º 2
0
 public string FetchNextValue()
 {
     if (!outputStreamPoller.Next(outputPacket))
     {
         Logger.LogWarning(TAG, $"Failed to fetch next packet from {outputStreamName}");
         return(null);
     }
     return(outputPacket.IsEmpty() ? null : outputPacket.Get());
 }
Ejemplo n.º 3
0
    private List <NormalizedLandmarkList> FetchNextMultiFaceLandmarks()
    {
        if (!multiFaceLandmarksStreamPoller.Next(multiFaceLandmarksPacket)) // blocks
        {
            Debug.LogWarning($"Failed to fetch next packet from {multiFaceLandmarksStream}");
            return(new List <NormalizedLandmarkList>());
        }

        return(multiFaceLandmarksPacket.GetValue());
    }
Ejemplo n.º 4
0
    private NormalizedRect FetchNextHandRect()
    {
        if (!handRectStreamPoller.Next(handRectPacket))
        {
            Debug.LogWarning($"Failed to fetch next packet from {handRectStream}");
            return(null);
        }

        return(handRectPacket.GetValue());
    }
Ejemplo n.º 5
0
    private List <Detection> FetchNextPalmDetections()
    {
        if (!palmDetectionsStreamPoller.Next(palmDetectionsPacket))
        {
            Debug.LogWarning($"Failed to fetch next packet from {palmDetectionsStream}");
            return(new List <Detection>());
        }

        return(palmDetectionsPacket.GetValue());
    }
Ejemplo n.º 6
0
    private ClassificationList FetchNextHandedness()
    {
        if (!handednessStreamPoller.Next(handednessPacket))
        {
            Debug.LogWarning($"Failed to fetch next packet from {handednessStream}");
            return(null);
        }

        return(handednessPacket.GetValue());
    }
Ejemplo n.º 7
0
    private List <NormalizedRect> FetchNextMultiPalmRects()
    {
        if (!multiPalmRectsStreamPoller.Next(multiPalmRectsPacket))
        {
            Debug.LogWarning($"Failed to fetch next packet from {multiPalmRectsStream}");
            return(new List <NormalizedRect>());
        }

        return(multiPalmRectsPacket.GetValue());
    }
Ejemplo n.º 8
0
    private bool FetchNextPalmDetectionsPresence()
    {
        if (!palmDetectionsPresenceStreamPoller.Next(palmDetectionsPresencePacket))
        {
            Debug.LogWarning($"Failed to fetch next packet from {palmDetectionsPresenceStream}");
            return(false);
        }

        return(palmDetectionsPresencePacket.GetValue());
    }
Ejemplo n.º 9
0
    private List <Detection> FetchNextFaceDetections()
    {
        if (!faceDetectionsStreamPoller.Next(faceDetectionsPacket)) // blocks
        {
            Debug.LogWarning($"Failed to fetch next packet from {faceDetectionsStream}");
            return(new List <Detection>());
        }

        return(faceDetectionsPacket.GetValue());
    }
Ejemplo n.º 10
0
    private bool FetchNextMultiFaceLandmarksPresence()
    {
        if (!multiFacelandmarksPresenceStreamPoller.Next(multiFaceLandmarksPresencePacket)) // blocks
        {
            Debug.LogWarning($"Failed to fetch next packet from {multiFaceLandmarksPresenceStream}");
            return(false);
        }

        return(multiFaceLandmarksPresencePacket.GetValue());
    }
Ejemplo n.º 11
0
    private bool FetchNextFaceDetectionsPresence()
    {
        if (!faceDetectionsPresenceStreamPoller.Next(faceDetectionsPresencePacket)) // blocks
        {
            Debug.LogWarning($"Failed to fetch next packet from {faceDetectionsPresenceStream}");
            return(false);
        }

        return(faceDetectionsPresencePacket.GetValue());
    }
Ejemplo n.º 12
0
    private List <NormalizedRect> FetchNextFaceRectsFromLandmarks()
    {
        if (!faceRectsFromLandmarksStreamPoller.Next(faceRectsFromLandmarksPacket)) // blocks
        {
            Debug.LogWarning($"Failed to fetch next packet from {faceRectsFromLandmarksStream}");
            return(new List <NormalizedRect>());
        }

        return(faceRectsFromLandmarksPacket.GetValue());
    }
Ejemplo n.º 13
0
    public override void RenderOutput(Texture2D texture, Color32[] pixelData)
    {
        if (!outputStreamPoller.Next(outputPacket))
        {
            Debug.LogWarning("Failed to fetch an output packet, rendering the input image");
            texture.SetPixels32(pixelData);
        }
        else
        {
            texture.SetPixels32(outputPacket.GetValue().GetColor32s());
        }

        texture.Apply();
    }
Ejemplo n.º 14
0
    /// <summary>
    ///   Fetch next value from <paramref name="poller" />.
    ///   Note that this method blocks the thread till the next value is fetched.
    ///   If the next value is empty, this method never returns.
    /// </summary>
    public T FetchNext <T>(OutputStreamPoller <T> poller, Packet <T> packet, string streamName = null, T failedValue = default(T))
    {
        if (!poller.Next(packet)) // blocks
        {
            if (streamName != null)
            {
                Debug.LogWarning($"Failed to fetch next packet from {streamName}");
            }

            return(failedValue);
        }

        return(packet.Get());
    }
Ejemplo n.º 15
0
    public override void RenderOutput(WebCamScreenController screenController, Color32[] pixelData)
    {
        var texture = screenController.GetScreen();

        if (!outputStreamPoller.Next(outputPacket))
        {
            Debug.LogWarning("Failed to fetch an output packet, rendering the input image");
            texture.SetPixels32(pixelData);
        }
        else
        {
            texture.SetPixels32(outputPacket.GetValue().GetColor32s());
        }

        texture.Apply();
    }
Ejemplo n.º 16
0
    public override void RenderOutput(WebCamScreenController screenController, PixelData pixelData)
    {
        var texture = screenController.GetScreen();

        if (!outputStreamPoller.Next(outputPacket))
        {
            Debug.LogWarning("Failed to fetch an output packet, rendering the input image");
            texture.SetPixels32(pixelData.Colors);
            texture.Apply();
            return;
        }

        ImageFrame outputFrame = null;

        var status = gpuHelper.RunInGlContext(() => {
            var gpuFrame       = outputPacket.Get();
            var gpuFrameFormat = gpuFrame.Format();
            var sourceTexture  = gpuHelper.CreateSourceTexture(gpuFrame);

            outputFrame = new ImageFrame(
                gpuFrameFormat.ImageFormatFor(), gpuFrame.Width(), gpuFrame.Height(), ImageFrame.kGlDefaultAlignmentBoundary);

            gpuHelper.BindFramebuffer(sourceTexture);
            var info = gpuFrameFormat.GlTextureInfoFor(0);

            Gl.ReadPixels(0, 0, sourceTexture.width, sourceTexture.height, info.glFormat, info.glType, outputFrame.MutablePixelData());
            Gl.Flush();

            sourceTexture.Release();

            return(Status.Ok(false));
        });

        if (status.ok)
        {
            texture.SetPixels32(outputFrame.GetColor32s());
        }
        else
        {
            Debug.LogError(status.ToString());
            texture.SetPixels32(pixelData.Colors);
        }

        texture.Apply();
    }
Ejemplo n.º 17
0
    public override void RenderOutput(Texture2D texture, Color32[] pixelData)
    {
        if (!outputStreamPoller.Next(outputPacket)) // blocks
        {
            Debug.LogWarning("Failed to fetch an output packet, rendering the input image");
            texture.SetPixels32(pixelData);
            texture.Apply();
            return;
        }

        ImageFrame outputFrame = null;

        var status = gpuHelper.RunInGlContext(() => {
            var gpuFrame       = outputPacket.GetValue();
            var gpuFrameFormat = gpuFrame.Format();
            var sourceTexture  = gpuHelper.CreateSourceTexture(gpuFrame);

            outputFrame = new ImageFrame(
                gpuFrameFormat.ImageFormatFor(), gpuFrame.Width(), gpuFrame.Height(), ImageFrame.kGlDefaultAlignmentBoundary);

            gpuHelper.BindFramebuffer(sourceTexture);
            var info = gpuFrameFormat.GlTextureInfoFor(0);

            UnsafeNativeMethods.GlReadPixels(0, 0, sourceTexture.Width(), sourceTexture.Height(), info.GlFormat(), info.GlType(), outputFrame.PixelDataPtr());
            UnsafeNativeMethods.GlFlush();

            sourceTexture.Release();

            return(Status.Ok(false));
        });

        if (status.IsOk())
        {
            texture.SetPixels32(outputFrame.GetColor32s());
        }
        else
        {
            Debug.LogError(status.ToString());
            texture.SetPixels32(pixelData);
        }

        texture.Apply();
    }
    public override void RenderOutput(WebCamScreenController screenController, TextureFrame textureFrame)
    {
#if UNITY_ANDROID
        // MediaPipe renders to the texture directly.
        return;
#else
        if (!outputStreamPoller.Next(outputPacket))
        {
            Debug.LogWarning("Failed to fetch an output packet, rendering the input image");
            screenController.DrawScreen(textureFrame);
            return;
        }

        using (var gpuBuffer = outputPacket.Get()) {
            ImageFrame imageFrame = null;

            gpuHelper.RunInGlContext(() => {
                var gpuBufferFormat = gpuBuffer.Format();
                var sourceTexture   = gpuHelper.CreateSourceTexture(gpuBuffer);

                imageFrame = new ImageFrame(
                    gpuBufferFormat.ImageFormatFor(), gpuBuffer.Width(), gpuBuffer.Height(), ImageFrame.kGlDefaultAlignmentBoundary);

                gpuHelper.BindFramebuffer(sourceTexture);
                var info = gpuBufferFormat.GlTextureInfoFor(0);

                Gl.ReadPixels(0, 0, sourceTexture.width, sourceTexture.height, info.glFormat, info.glType, imageFrame.MutablePixelData());
                Gl.Flush();

                sourceTexture.Release();

                return(Status.Ok(false));
            }).AssertOk();

            if (imageFrame != null) // always true
            {
                screenController.DrawScreen(imageFrame);
            }
        }
#endif
    }
Ejemplo n.º 19
0
    private List <Landmark[]> FetchNextLandmarks()
    {
        if (!landmarkPresenceStreamPoller.Next(landmarkPresencePacket)) // blocks
        {
            return(new List <Landmark[]>());
        }

        bool isLandmarkPresent = landmarkPresencePacket.GetValue();

        if (!isLandmarkPresent)
        {
            return(new List <Landmark[]>());
        }

        if (!landmarkStreamPoller.Next(landmarkListPacket))
        {
            return(new List <Landmark[]>());
        }

        return(landmarkListPacket.GetValue());
    }
    private ImageFrame FetchNextHairMask()
    {
        if (!hairMaskStreamPoller.Next(hairMaskPacket))
        {
            Debug.LogWarning($"Failed to fetch next packet from {hairMaskStream}");
            return(null);
        }

        ImageFrame outputFrame = null;

        var status = gpuHelper.RunInGlContext(() => {
            var gpuFrame       = hairMaskPacket.Get();
            var gpuFrameFormat = gpuFrame.Format();
            var sourceTexture  = gpuHelper.CreateSourceTexture(gpuFrame);

            outputFrame = new ImageFrame(
                gpuFrameFormat.ImageFormatFor(), gpuFrame.Width(), gpuFrame.Height(), ImageFrame.kGlDefaultAlignmentBoundary);

            gpuHelper.BindFramebuffer(sourceTexture);
            var info = gpuFrameFormat.GlTextureInfoFor(0);

            Gl.ReadPixels(0, 0, sourceTexture.width, sourceTexture.height, info.glFormat, info.glType, outputFrame.MutablePixelData());
            Gl.Flush();

            sourceTexture.Release();

            return(Status.Ok(false));
        });

        if (!status.ok)
        {
            Debug.LogError(status.ToString());
        }

        return(outputFrame);
    }