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>()},