Rename "Bound" struct to "Rect" and remove unused "Landmark" struct.
PiperOrigin-RevId: 482255889
This commit is contained in:
parent
8426428de3
commit
c260074abb
|
@ -17,8 +17,8 @@ package(default_visibility = ["//mediapipe/tasks:internal"])
|
||||||
licenses(["notice"])
|
licenses(["notice"])
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "landmarks_detection",
|
name = "rect",
|
||||||
hdrs = ["landmarks_detection.h"],
|
hdrs = ["rect.h"],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
|
|
|
@ -13,26 +13,18 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==============================================================================*/
|
==============================================================================*/
|
||||||
|
|
||||||
#ifndef MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_LANDMARKS_DETECTION_H_
|
#ifndef MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_RECT_H_
|
||||||
#define MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_LANDMARKS_DETECTION_H_
|
#define MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_RECT_H_
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
// Sturcts holding landmarks related data structure for hand landmarker, pose
|
|
||||||
// detector, face mesher, etc.
|
|
||||||
namespace mediapipe::tasks::components::containers {
|
namespace mediapipe::tasks::components::containers {
|
||||||
|
|
||||||
// x and y are in [0,1] range with origin in top left in input image space.
|
// Defines a rectangle, used e.g. as part of detection results or as input
|
||||||
// If model provides z, z is in the same scale as x. origin is in the center
|
// region-of-interest.
|
||||||
// of the face.
|
//
|
||||||
struct Landmark {
|
// The coordinates are normalized wrt the image dimensions, i.e. generally in
|
||||||
float x;
|
// [0,1] but they may exceed these bounds if describing a region overlapping the
|
||||||
float y;
|
// image. The origin is on the top-left corner of the image.
|
||||||
float z;
|
struct Rect {
|
||||||
};
|
|
||||||
|
|
||||||
// [0, 1] range in input image space
|
|
||||||
struct Bound {
|
|
||||||
float left;
|
float left;
|
||||||
float top;
|
float top;
|
||||||
float right;
|
float right;
|
||||||
|
@ -40,4 +32,4 @@ struct Bound {
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mediapipe::tasks::components::containers
|
} // namespace mediapipe::tasks::components::containers
|
||||||
#endif // MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_LANDMARKS_DETECTION_H_
|
#endif // MEDIAPIPE_TASKS_CC_COMPONENTS_CONTAINERS_RECT_H_
|
|
@ -57,7 +57,7 @@ cc_library(
|
||||||
"//mediapipe/framework/formats:classification_cc_proto",
|
"//mediapipe/framework/formats:classification_cc_proto",
|
||||||
"//mediapipe/framework/formats:landmark_cc_proto",
|
"//mediapipe/framework/formats:landmark_cc_proto",
|
||||||
"//mediapipe/framework/formats:rect_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_duplicates_finder",
|
||||||
"//mediapipe/tasks/cc/vision/utils:landmarks_utils",
|
"//mediapipe/tasks/cc/vision/utils:landmarks_utils",
|
||||||
"@com_google_absl//absl/algorithm:container",
|
"@com_google_absl//absl/algorithm:container",
|
||||||
|
|
|
@ -34,7 +34,7 @@ limitations under the License.
|
||||||
#include "mediapipe/framework/formats/classification.pb.h"
|
#include "mediapipe/framework/formats/classification.pb.h"
|
||||||
#include "mediapipe/framework/formats/landmark.pb.h"
|
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||||
#include "mediapipe/framework/formats/rect.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_duplicates_finder.h"
|
||||||
#include "mediapipe/tasks/cc/vision/utils/landmarks_utils.h"
|
#include "mediapipe/tasks/cc/vision/utils/landmarks_utils.h"
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace {
|
||||||
using ::mediapipe::api2::Input;
|
using ::mediapipe::api2::Input;
|
||||||
using ::mediapipe::api2::Output;
|
using ::mediapipe::api2::Output;
|
||||||
using ::mediapipe::api2::builder::Source;
|
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::CalculateIOU;
|
||||||
using ::mediapipe::tasks::vision::utils::DuplicatesFinder;
|
using ::mediapipe::tasks::vision::utils::DuplicatesFinder;
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ absl::StatusOr<float> HandBaselineDistance(
|
||||||
return distance;
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bound CalculateBound(const NormalizedLandmarkList& list) {
|
Rect CalculateBound(const NormalizedLandmarkList& list) {
|
||||||
constexpr float kMinInitialValue = std::numeric_limits<float>::max();
|
constexpr float kMinInitialValue = std::numeric_limits<float>::max();
|
||||||
constexpr float kMaxInitialValue = std::numeric_limits<float>::lowest();
|
constexpr float kMaxInitialValue = std::numeric_limits<float>::lowest();
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ class HandDuplicatesFinder : public DuplicatesFinder {
|
||||||
const int num = multi_landmarks.size();
|
const int num = multi_landmarks.size();
|
||||||
std::vector<float> baseline_distances;
|
std::vector<float> baseline_distances;
|
||||||
baseline_distances.reserve(num);
|
baseline_distances.reserve(num);
|
||||||
std::vector<Bound> bounds;
|
std::vector<Rect> bounds;
|
||||||
bounds.reserve(num);
|
bounds.reserve(num);
|
||||||
for (const NormalizedLandmarkList& list : multi_landmarks) {
|
for (const NormalizedLandmarkList& list : multi_landmarks) {
|
||||||
ASSIGN_OR_RETURN(const float baseline_distance,
|
ASSIGN_OR_RETURN(const float baseline_distance,
|
||||||
|
|
|
@ -94,7 +94,7 @@ cc_library(
|
||||||
name = "landmarks_utils",
|
name = "landmarks_utils",
|
||||||
srcs = ["landmarks_utils.cc"],
|
srcs = ["landmarks_utils.cc"],
|
||||||
hdrs = ["landmarks_utils.h"],
|
hdrs = ["landmarks_utils.h"],
|
||||||
deps = ["//mediapipe/tasks/cc/components/containers:landmarks_detection"],
|
deps = ["//mediapipe/tasks/cc/components/containers:rect"],
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_test(
|
cc_test(
|
||||||
|
@ -103,6 +103,6 @@ cc_test(
|
||||||
deps = [
|
deps = [
|
||||||
":landmarks_utils",
|
":landmarks_utils",
|
||||||
"//mediapipe/framework/port:gtest_main",
|
"//mediapipe/framework/port:gtest_main",
|
||||||
"//mediapipe/tasks/cc/components/containers:landmarks_detection",
|
"//mediapipe/tasks/cc/components/containers:rect",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,15 +18,17 @@ limitations under the License.
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "mediapipe/tasks/cc/components/containers/rect.h"
|
||||||
|
|
||||||
namespace mediapipe::tasks::vision::utils {
|
namespace mediapipe::tasks::vision::utils {
|
||||||
|
|
||||||
using ::mediapipe::tasks::components::containers::Bound;
|
using ::mediapipe::tasks::components::containers::Rect;
|
||||||
|
|
||||||
float CalculateArea(const Bound& bound) {
|
float CalculateArea(const Rect& rect) {
|
||||||
return (bound.right - bound.left) * (bound.bottom - bound.top);
|
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<float>(a.left, b.left);
|
const float intersection_left = std::max<float>(a.left, b.left);
|
||||||
const float intersection_top = std::max<float>(a.top, b.top);
|
const float intersection_top = std::max<float>(a.top, b.top);
|
||||||
const float intersection_right = std::min<float>(a.right, b.right);
|
const float intersection_right = std::min<float>(a.right, b.right);
|
||||||
|
@ -36,7 +38,7 @@ float CalculateIntersectionArea(const Bound& a, const Bound& b) {
|
||||||
std::max<float>(intersection_right - intersection_left, 0.0);
|
std::max<float>(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_a = CalculateArea(a);
|
||||||
const float area_b = CalculateArea(b);
|
const float area_b = CalculateArea(b);
|
||||||
if (area_a <= 0 || area_b <= 0) return 0.0;
|
if (area_a <= 0 || area_b <= 0) return 0.0;
|
||||||
|
|
|
@ -22,20 +22,20 @@ limitations under the License.
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "mediapipe/tasks/cc/components/containers/landmarks_detection.h"
|
#include "mediapipe/tasks/cc/components/containers/rect.h"
|
||||||
|
|
||||||
namespace mediapipe::tasks::vision::utils {
|
namespace mediapipe::tasks::vision::utils {
|
||||||
|
|
||||||
// Calculates intersection over union for two bounds.
|
// Calculates intersection over union for two bounds.
|
||||||
float CalculateIOU(const components::containers::Bound& a,
|
float CalculateIOU(const components::containers::Rect& a,
|
||||||
const components::containers::Bound& b);
|
const components::containers::Rect& b);
|
||||||
|
|
||||||
// Calculates area for face bound
|
// 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
|
// Calucates intersection area of two face bounds
|
||||||
float CalculateIntersectionArea(const components::containers::Bound& a,
|
float CalculateIntersectionArea(const components::containers::Rect& a,
|
||||||
const components::containers::Bound& b);
|
const components::containers::Rect& b);
|
||||||
} // namespace mediapipe::tasks::vision::utils
|
} // namespace mediapipe::tasks::vision::utils
|
||||||
|
|
||||||
#endif // MEDIAPIPE_TASKS_CC_VISION_UTILS_LANDMARKS_UTILS_H_
|
#endif // MEDIAPIPE_TASKS_CC_VISION_UTILS_LANDMARKS_UTILS_H_
|
||||||
|
|
Loading…
Reference in New Issue
Block a user