diff --git a/mediapipe/tasks/cc/components/containers/BUILD b/mediapipe/tasks/cc/components/containers/BUILD index 33d3e4457..af51d0c37 100644 --- a/mediapipe/tasks/cc/components/containers/BUILD +++ b/mediapipe/tasks/cc/components/containers/BUILD @@ -17,8 +17,8 @@ package(default_visibility = ["//mediapipe/tasks:internal"]) licenses(["notice"]) cc_library( - name = "landmarks_detection", - hdrs = ["landmarks_detection.h"], + name = "rect", + hdrs = ["rect.h"], ) cc_library( diff --git a/mediapipe/tasks/cc/components/containers/landmarks_detection.h b/mediapipe/tasks/cc/components/containers/rect.h similarity index 57% rename from mediapipe/tasks/cc/components/containers/landmarks_detection.h rename to mediapipe/tasks/cc/components/containers/rect.h index 7339954d8..3f5432cf2 100644 --- a/mediapipe/tasks/cc/components/containers/landmarks_detection.h +++ b/mediapipe/tasks/cc/components/containers/rect.h @@ -13,26 +13,18 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_LANDMARKS_DETECTION_H_ -#define MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_LANDMARKS_DETECTION_H_ +#ifndef MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_RECT_H_ +#define MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_RECT_H_ -#include - -// Sturcts holding landmarks related data structure for hand landmarker, pose -// detector, face mesher, etc. namespace mediapipe::tasks::components::containers { -// x and y are in [0,1] range with origin in top left in input image space. -// If model provides z, z is in the same scale as x. origin is in the center -// of the face. -struct Landmark { - float x; - float y; - float z; -}; - -// [0, 1] range in input image space -struct Bound { +// Defines a rectangle, used e.g. as part of detection results or as input +// region-of-interest. +// +// The coordinates are normalized wrt the image dimensions, i.e. generally in +// [0,1] but they may exceed these bounds if describing a region overlapping the +// image. The origin is on the top-left corner of the image. +struct Rect { float left; float top; float right; @@ -40,4 +32,4 @@ struct Bound { }; } // namespace mediapipe::tasks::components::containers -#endif // MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_LANDMARKS_DETECTION_H_ +#endif // MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_RECT_H_ diff --git a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD index 3b82153eb..f45681fb3 100644 --- a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD +++ b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/BUILD @@ -57,7 +57,7 @@ cc_library( "//mediapipe/framework/formats:classification_cc_proto", "//mediapipe/framework/formats:landmark_cc_proto", "//mediapipe/framework/formats:rect_cc_proto", - "//mediapipe/tasks/cc/components/containers:landmarks_detection", + "//mediapipe/tasks/cc/components/containers:rect", "//mediapipe/tasks/cc/vision/utils:landmarks_duplicates_finder", "//mediapipe/tasks/cc/vision/utils:landmarks_utils", "@com_google_absl//absl/algorithm:container", diff --git a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_landmarks_deduplication_calculator.cc b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_landmarks_deduplication_calculator.cc index 8920ea0cb..5a5baa50e 100644 --- a/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_landmarks_deduplication_calculator.cc +++ b/mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_landmarks_deduplication_calculator.cc @@ -34,7 +34,7 @@ limitations under the License. #include "mediapipe/framework/formats/classification.pb.h" #include "mediapipe/framework/formats/landmark.pb.h" #include "mediapipe/framework/formats/rect.pb.h" -#include "mediapipe/tasks/cc/components/containers/landmarks_detection.h" +#include "mediapipe/tasks/cc/components/containers/rect.h" #include "mediapipe/tasks/cc/vision/utils/landmarks_duplicates_finder.h" #include "mediapipe/tasks/cc/vision/utils/landmarks_utils.h" @@ -44,7 +44,7 @@ namespace { using ::mediapipe::api2::Input; using ::mediapipe::api2::Output; using ::mediapipe::api2::builder::Source; -using ::mediapipe::tasks::components::containers::Bound; +using ::mediapipe::tasks::components::containers::Rect; using ::mediapipe::tasks::vision::utils::CalculateIOU; using ::mediapipe::tasks::vision::utils::DuplicatesFinder; @@ -126,7 +126,7 @@ absl::StatusOr HandBaselineDistance( return distance; } -Bound CalculateBound(const NormalizedLandmarkList& list) { +Rect CalculateBound(const NormalizedLandmarkList& list) { constexpr float kMinInitialValue = std::numeric_limits::max(); constexpr float kMaxInitialValue = std::numeric_limits::lowest(); @@ -172,7 +172,7 @@ class HandDuplicatesFinder : public DuplicatesFinder { const int num = multi_landmarks.size(); std::vector baseline_distances; baseline_distances.reserve(num); - std::vector bounds; + std::vector bounds; bounds.reserve(num); for (const NormalizedLandmarkList& list : multi_landmarks) { ASSIGN_OR_RETURN(const float baseline_distance, diff --git a/mediapipe/tasks/cc/vision/utils/BUILD b/mediapipe/tasks/cc/vision/utils/BUILD index c796798df..fda33bea5 100644 --- a/mediapipe/tasks/cc/vision/utils/BUILD +++ b/mediapipe/tasks/cc/vision/utils/BUILD @@ -94,7 +94,7 @@ cc_library( name = "landmarks_utils", srcs = ["landmarks_utils.cc"], hdrs = ["landmarks_utils.h"], - deps = ["//mediapipe/tasks/cc/components/containers:landmarks_detection"], + deps = ["//mediapipe/tasks/cc/components/containers:rect"], ) cc_test( @@ -103,6 +103,6 @@ cc_test( deps = [ ":landmarks_utils", "//mediapipe/framework/port:gtest_main", - "//mediapipe/tasks/cc/components/containers:landmarks_detection", + "//mediapipe/tasks/cc/components/containers:rect", ], ) diff --git a/mediapipe/tasks/cc/vision/utils/landmarks_utils.cc b/mediapipe/tasks/cc/vision/utils/landmarks_utils.cc index 5ec898f15..2ce9e2454 100644 --- a/mediapipe/tasks/cc/vision/utils/landmarks_utils.cc +++ b/mediapipe/tasks/cc/vision/utils/landmarks_utils.cc @@ -18,15 +18,17 @@ limitations under the License. #include #include +#include "mediapipe/tasks/cc/components/containers/rect.h" + namespace mediapipe::tasks::vision::utils { -using ::mediapipe::tasks::components::containers::Bound; +using ::mediapipe::tasks::components::containers::Rect; -float CalculateArea(const Bound& bound) { - return (bound.right - bound.left) * (bound.bottom - bound.top); +float CalculateArea(const Rect& rect) { + return (rect.right - rect.left) * (rect.bottom - rect.top); } -float CalculateIntersectionArea(const Bound& a, const Bound& b) { +float CalculateIntersectionArea(const Rect& a, const Rect& b) { const float intersection_left = std::max(a.left, b.left); const float intersection_top = std::max(a.top, b.top); const float intersection_right = std::min(a.right, b.right); @@ -36,7 +38,7 @@ float CalculateIntersectionArea(const Bound& a, const Bound& b) { std::max(intersection_right - intersection_left, 0.0); } -float CalculateIOU(const Bound& a, const Bound& b) { +float CalculateIOU(const Rect& a, const Rect& b) { const float area_a = CalculateArea(a); const float area_b = CalculateArea(b); if (area_a <= 0 || area_b <= 0) return 0.0; diff --git a/mediapipe/tasks/cc/vision/utils/landmarks_utils.h b/mediapipe/tasks/cc/vision/utils/landmarks_utils.h index b42eae0b6..73114d2ef 100644 --- a/mediapipe/tasks/cc/vision/utils/landmarks_utils.h +++ b/mediapipe/tasks/cc/vision/utils/landmarks_utils.h @@ -22,20 +22,20 @@ limitations under the License. #include #include -#include "mediapipe/tasks/cc/components/containers/landmarks_detection.h" +#include "mediapipe/tasks/cc/components/containers/rect.h" namespace mediapipe::tasks::vision::utils { // Calculates intersection over union for two bounds. -float CalculateIOU(const components::containers::Bound& a, - const components::containers::Bound& b); +float CalculateIOU(const components::containers::Rect& a, + const components::containers::Rect& b); // Calculates area for face bound -float CalculateArea(const components::containers::Bound& bound); +float CalculateArea(const components::containers::Rect& rect); // Calucates intersection area of two face bounds -float CalculateIntersectionArea(const components::containers::Bound& a, - const components::containers::Bound& b); +float CalculateIntersectionArea(const components::containers::Rect& a, + const components::containers::Rect& b); } // namespace mediapipe::tasks::vision::utils #endif // MEDIAPIPE_TASKS_CC_VISION_UTILS_LANDMARKS_UTILS_H_