update detection result to include optional keypoints.

PiperOrigin-RevId: 511538880
This commit is contained in:
MediaPipe Team 2023-02-22 10:48:30 -08:00 committed by Copybara-Service
parent c026f935bc
commit fbbc13d756
2 changed files with 34 additions and 0 deletions

View File

@ -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<NormalizedKeypoint>();
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;
}

View File

@ -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<std::string> label;
// optional score of the keypoint.
std::optional<float> score;
};
// Detection for a single bounding box.
struct Detection {
// A vector of detected categories.
std::vector<Category> 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<std::vector<NormalizedKeypoint>> keypoints = std::nullopt;
};
// Detection results of a model.