From 64deb791dc6814858e6f19133ee691d72b80993e Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Tue, 11 Oct 2022 15:35:37 -0700 Subject: [PATCH] Fix empty packet bug with no hands detected. PiperOrigin-RevId: 480469392 --- .../gesture_recognizer/gesture_recognizer.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mediapipe/tasks/cc/vision/gesture_recognizer/gesture_recognizer.cc b/mediapipe/tasks/cc/vision/gesture_recognizer/gesture_recognizer.cc index ca5deee7f..e0d1473c2 100644 --- a/mediapipe/tasks/cc/vision/gesture_recognizer/gesture_recognizer.cc +++ b/mediapipe/tasks/cc/vision/gesture_recognizer/gesture_recognizer.cc @@ -180,6 +180,15 @@ absl::StatusOr> GestureRecognizer::Create( if (status_or_packets.value()[kImageOutStreamName].IsEmpty()) { return; } + Packet image_packet = status_or_packets.value()[kImageOutStreamName]; + if (status_or_packets.value()[kHandGesturesStreamName].IsEmpty()) { + Packet empty_packet = + status_or_packets.value()[kHandGesturesStreamName]; + result_callback( + {{{}, {}, {}, {}}}, image_packet.Get(), + empty_packet.Timestamp().Value() / kMicroSecondsPerMilliSecond); + return; + } Packet gesture_packet = status_or_packets.value()[kHandGesturesStreamName]; Packet handedness_packet = @@ -188,7 +197,6 @@ absl::StatusOr> GestureRecognizer::Create( status_or_packets.value()[kHandLandmarksStreamName]; Packet hand_world_landmarks_packet = status_or_packets.value()[kHandWorldLandmarksStreamName]; - Packet image_packet = status_or_packets.value()[kImageOutStreamName]; result_callback( {{gesture_packet.Get>(), handedness_packet.Get>(), @@ -218,6 +226,9 @@ absl::StatusOr GestureRecognizer::Recognize( ASSIGN_OR_RETURN(auto output_packets, ProcessImageData({{kImageInStreamName, MakePacket(std::move(image))}})); + if (output_packets[kHandGesturesStreamName].IsEmpty()) { + return {{{}, {}, {}, {}}}; + } return { {/* gestures= */ {output_packets[kHandGesturesStreamName] .Get>()}, @@ -247,6 +258,9 @@ absl::StatusOr GestureRecognizer::RecognizeForVideo( {{kImageInStreamName, MakePacket(std::move(image)) .At(Timestamp(timestamp_ms * kMicroSecondsPerMilliSecond))}})); + if (output_packets[kHandGesturesStreamName].IsEmpty()) { + return {{{}, {}, {}, {}}}; + } return { {/* gestures= */ {output_packets[kHandGesturesStreamName] .Get>()},