From fbbc13d75666a4bc6a457290112f5bfaf495699a Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Wed, 22 Feb 2023 10:48:30 -0800 Subject: [PATCH] update detection result to include optional keypoints. PiperOrigin-RevId: 511538880 --- .../components/containers/detection_result.cc | 15 +++++++++++++++ .../components/containers/detection_result.h | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/mediapipe/tasks/cc/components/containers/detection_result.cc b/mediapipe/tasks/cc/components/containers/detection_result.cc index 38126f917..83745ca5d 100644 --- a/mediapipe/tasks/cc/components/containers/detection_result.cc +++ b/mediapipe/tasks/cc/components/containers/detection_result.cc @@ -55,6 +55,21 @@ Detection ConvertToDetectionResult( bounding_box_proto.ymin() + bounding_box_proto.height(); } detection.bounding_box = bounding_box; + if (!detection_proto.location_data().relative_keypoints().empty()) { + detection.keypoints = std::vector(); + detection.keypoints->reserve( + detection_proto.location_data().relative_keypoints_size()); + for (const auto& keypoint : + detection_proto.location_data().relative_keypoints()) { + detection.keypoints->push_back( + {keypoint.x(), keypoint.y(), + keypoint.has_keypoint_label() + ? std::make_optional(keypoint.keypoint_label()) + : std::nullopt, + keypoint.has_score() ? std::make_optional(keypoint.score()) + : std::nullopt}); + } + } return detection; } diff --git a/mediapipe/tasks/cc/components/containers/detection_result.h b/mediapipe/tasks/cc/components/containers/detection_result.h index 546f324d6..9ea2a547c 100644 --- a/mediapipe/tasks/cc/components/containers/detection_result.h +++ b/mediapipe/tasks/cc/components/containers/detection_result.h @@ -26,12 +26,31 @@ limitations under the License. namespace mediapipe::tasks::components::containers { +// A keypoint, defined by the coordinates (x, y), normalized +// by the image dimensions. +struct NormalizedKeypoint { + // x in normalized image coordinates. + float x; + // y in normalized image coordinates. + float y; + // optional label of the keypoint. + std::optional label; + // optional score of the keypoint. + std::optional score; +}; + // Detection for a single bounding box. struct Detection { // A vector of detected categories. std::vector categories; // The bounding box location. Rect bounding_box; + // Optional list of keypoints associated with the detection. Keypoints + // represent interesting points related to the detection. For example, the + // keypoints represent the eye, ear and mouth from face detection model. Or + // in the template matching detection, e.g. KNIFT, they can represent the + // feature points for template matching. + std::optional> keypoints = std::nullopt; }; // Detection results of a model.