diff --git a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_android.txt b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_android.txt index 4e3b3445d..b9c2a3eec 100644 --- a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_android.txt +++ b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_android.txt @@ -17,7 +17,6 @@ # CHANGES: # - Add ImageTransformationCalculator and rotate the input # - Remove PoseRendererGpu -# - Add PacketPresenceCalculators # MediaPipe graph that performs upper-body pose tracking with TensorFlow Lite on GPU. @@ -26,8 +25,6 @@ input_stream: "input_video" output_stream: "pose_landmarks" output_stream: "pose_world_landmarks" output_stream: "pose_detection" -output_stream: "pose_landmarks_presence" -output_stream: "pose_detection_presence" # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes @@ -42,7 +39,7 @@ output_stream: "pose_detection_presence" node { calculator: "FlowLimiterCalculator" input_stream: "input_video" - input_stream: "FINISHED:pose_detection_presence" + input_stream: "FINISHED:pose_landmarks" input_stream_info: { tag_index: "FINISHED" back_edge: true @@ -70,15 +67,3 @@ node { output_stream: "DETECTION:pose_detection" output_stream: "ROI_FROM_LANDMARKS:roi_from_landmarks" } - -node { - calculator: "PacketPresenceCalculator" - input_stream: "PACKET:pose_landmarks" - output_stream: "PRESENCE:pose_landmarks_presence" -} - -node { - calculator: "PacketPresenceCalculator" - input_stream: "PACKET:pose_detection" - output_stream: "PRESENCE:pose_detection_presence" -} diff --git a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_cpu.txt b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_cpu.txt index a2ce2b052..9f2a504e0 100644 --- a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_cpu.txt +++ b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_cpu.txt @@ -17,7 +17,6 @@ # CHANGES: # - Add ImageTransformationCalculator and rotate the input # - Remove PoseRendererCpu -# - Add PacketPresenceCalculators # MediaPipe graph that performs upper-body pose tracking with TensorFlow Lite on CPU. @@ -26,8 +25,6 @@ input_stream: "input_video" output_stream: "pose_landmarks" output_stream: "pose_world_landmarks" output_stream: "pose_detection" -output_stream: "pose_landmarks_presence" -output_stream: "pose_detection_presence" # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes @@ -42,7 +39,7 @@ output_stream: "pose_detection_presence" node { calculator: "FlowLimiterCalculator" input_stream: "input_video" - input_stream: "FINISHED:pose_detection_presence" + input_stream: "FINISHED:pose_landmarks" input_stream_info: { tag_index: "FINISHED" back_edge: true @@ -70,15 +67,3 @@ node { output_stream: "DETECTION:pose_detection" output_stream: "ROI_FROM_LANDMARKS:roi_from_landmarks" } - -node { - calculator: "PacketPresenceCalculator" - input_stream: "PACKET:pose_landmarks" - output_stream: "PRESENCE:pose_landmarks_presence" -} - -node { - calculator: "PacketPresenceCalculator" - input_stream: "PACKET:pose_detection" - output_stream: "PRESENCE:pose_detection_presence" -} diff --git a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_gpu.txt b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_gpu.txt index e673a13f6..ccc64526c 100644 --- a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_gpu.txt +++ b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Resources/pose_tracking_desktop_gpu.txt @@ -18,7 +18,6 @@ # - `input_video` is ImageFrame (ImageFrameToGpuBufferCalculator converts it into GpuBuffer) # - Add ImageTransformationCalculator and rotate the input # - Remove PoseRendererGpu -# - Add PacketPresenceCalculators # MediaPipe graph that performs upper-body pose tracking with TensorFlow Lite on GPU. @@ -27,8 +26,6 @@ input_stream: "input_video" output_stream: "pose_landmarks" output_stream: "pose_world_landmarks" output_stream: "pose_detection" -output_stream: "pose_landmarks_presence" -output_stream: "pose_detection_presence" # Throttles the images flowing downstream for flow control. It passes through # the very first incoming image unaltered, and waits for downstream nodes @@ -43,7 +40,7 @@ output_stream: "pose_detection_presence" node { calculator: "FlowLimiterCalculator" input_stream: "input_video" - input_stream: "FINISHED:pose_detection_presence" + input_stream: "FINISHED:pose_landmarks" input_stream_info: { tag_index: "FINISHED" back_edge: true @@ -77,15 +74,3 @@ node { output_stream: "DETECTION:pose_detection" output_stream: "ROI_FROM_LANDMARKS:roi_from_landmarks" } - -node { - calculator: "PacketPresenceCalculator" - input_stream: "PACKET:pose_landmarks" - output_stream: "PRESENCE:pose_landmarks_presence" -} - -node { - calculator: "PacketPresenceCalculator" - input_stream: "PACKET:pose_detection" - output_stream: "PRESENCE:pose_detection_presence" -} diff --git a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingGraph.cs b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingGraph.cs index 20030ac03..d0a616066 100644 --- a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingGraph.cs +++ b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingGraph.cs @@ -23,14 +23,6 @@ enum ModelComplexity { private OutputStreamPoller poseDetectionStreamPoller; private DetectionPacket poseDetectionPacket; - private const string poseLandmarksPresenceStream = "pose_landmarks_presence"; - private OutputStreamPoller poseLandmarksPresenceStreamPoller; - private BoolPacket poseLandmarksPresencePacket; - - private const string poseDetectionPresenceStream = "pose_detection_presence"; - private OutputStreamPoller poseDetectionPresenceStreamPoller; - private BoolPacket poseDetectionPresencePacket; - private SidePacket sidePacket; public override Status StartRun() { @@ -43,12 +35,6 @@ public override Status StartRun() { poseDetectionStreamPoller = graph.AddOutputStreamPoller(poseDetectionStream).Value(); poseDetectionPacket = new DetectionPacket(); - poseLandmarksPresenceStreamPoller = graph.AddOutputStreamPoller(poseLandmarksPresenceStream).Value(); - poseLandmarksPresencePacket = new BoolPacket(); - - poseDetectionPresenceStreamPoller = graph.AddOutputStreamPoller(poseDetectionPresenceStream).Value(); - poseDetectionPresencePacket = new BoolPacket(); - sidePacket = new SidePacket(); sidePacket.Emplace("model_complexity", new IntPacket((int)modelComplexity)); sidePacket.Emplace("smooth_landmarks", new BoolPacket(smoothLandmarks)); @@ -64,18 +50,16 @@ public override void RenderOutput(WebCamScreenController screenController, Textu } private PoseTrackingValue FetchNextPoseTrackingValue() { - if (!FetchNextPoseLandmarksPresence()) { - return new PoseTrackingValue(); + NormalizedLandmarkList poseLandmarks = null; + if (poseLandmarksStreamPoller.QueueSize() > 0) { + poseLandmarks = FetchNextPoseLandmarks(); } - var poseLandmarks = FetchNextPoseLandmarks(); - - if (!FetchNextPoseDetectionPresence()) { - return new PoseTrackingValue(poseLandmarks); + Detection poseDetection = null; + if (poseDetectionStreamPoller.QueueSize() > 0) { + poseDetection = FetchNextPoseDetection(); } - var poseDetection = FetchNextPoseDetection(); - return new PoseTrackingValue(poseLandmarks, poseDetection); } @@ -91,14 +75,6 @@ private Detection FetchNextPoseDetection() { return FetchNext(poseDetectionStreamPoller, poseDetectionPacket, poseDetectionStream); } - private bool FetchNextPoseLandmarksPresence() { - return FetchNext(poseLandmarksPresenceStreamPoller, poseLandmarksPresencePacket, poseLandmarksPresenceStream); - } - - private bool FetchNextPoseDetectionPresence() { - return FetchNext(poseDetectionPresenceStreamPoller, poseDetectionPresencePacket, poseDetectionPresenceStream); - } - private void RenderAnnotation(WebCamScreenController screenController, PoseTrackingValue value) { // NOTE: input image is flipped GetComponent().Draw(screenController.transform, value.PoseLandmarkList, value.PoseDetection, true); diff --git a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingValue.cs b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingValue.cs index 9350c805e..f3b5506a6 100644 --- a/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingValue.cs +++ b/Assets/Mediapipe/Samples/Graphs/PoseTracking/Scripts/PoseTrackingValue.cs @@ -5,8 +5,8 @@ class PoseTrackingValue { public readonly Detection PoseDetection; public PoseTrackingValue(NormalizedLandmarkList landmarkList, Detection detection) { - PoseLandmarkList = landmarkList; - PoseDetection = detection; + PoseLandmarkList = landmarkList == null ? new NormalizedLandmarkList() : landmarkList; + PoseDetection = detection == null ? new Detection() : detection; } public PoseTrackingValue(NormalizedLandmarkList landmarkList) : this(landmarkList, new Detection()) {} diff --git a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/OutputStreamPoller.cs b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/OutputStreamPoller.cs index 5937f5881..8dcd8e1b0 100644 --- a/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/OutputStreamPoller.cs +++ b/Packages/com.github.homuler.mediapipe/Runtime/Scripts/Framework/OutputStreamPoller.cs @@ -14,5 +14,20 @@ public bool Next(Packet packet) { GC.KeepAlive(this); return result; } + + public void Reset() { + UnsafeNativeMethods.mp_OutputStreamPoller__Reset(mpPtr).Assert(); + } + + public void SetMaxQueueSize(int queueSize) { + UnsafeNativeMethods.mp_OutputStreamPoller__SetMaxQueueSize(mpPtr, queueSize).Assert(); + } + + public int QueueSize() { + UnsafeNativeMethods.mp_OutputStreamPoller__QueueSize(mpPtr, out var result).Assert(); + + GC.KeepAlive(this); + return result; + } } }