Rename hand landmarker related graphs.
PiperOrigin-RevId: 478706652
This commit is contained in:
parent
2cb9ebb5e3
commit
25e424baaf
|
@ -66,7 +66,7 @@ cc_library(
|
||||||
"//mediapipe/tasks/cc/vision/gesture_recognizer/calculators:landmarks_to_matrix_calculator",
|
"//mediapipe/tasks/cc/vision/gesture_recognizer/calculators:landmarks_to_matrix_calculator",
|
||||||
"//mediapipe/tasks/cc/vision/gesture_recognizer/calculators:landmarks_to_matrix_calculator_cc_proto",
|
"//mediapipe/tasks/cc/vision/gesture_recognizer/calculators:landmarks_to_matrix_calculator_cc_proto",
|
||||||
"//mediapipe/tasks/cc/vision/gesture_recognizer/proto:hand_gesture_recognizer_graph_options_cc_proto",
|
"//mediapipe/tasks/cc/vision/gesture_recognizer/proto:hand_gesture_recognizer_graph_options_cc_proto",
|
||||||
"//mediapipe/tasks/cc/vision/hand_landmarker:hand_landmarker_subgraph",
|
"//mediapipe/tasks/cc/vision/hand_landmarker:hand_landmarks_detector_graph",
|
||||||
"//mediapipe/tasks/cc/vision/utils:image_tensor_specs",
|
"//mediapipe/tasks/cc/vision/utils:image_tensor_specs",
|
||||||
"//mediapipe/tasks/metadata:metadata_schema_cc",
|
"//mediapipe/tasks/metadata:metadata_schema_cc",
|
||||||
"@com_google_absl//absl/status",
|
"@com_google_absl//absl/status",
|
||||||
|
|
|
@ -19,10 +19,10 @@ package(default_visibility = [
|
||||||
licenses(["notice"])
|
licenses(["notice"])
|
||||||
|
|
||||||
cc_library(
|
cc_library(
|
||||||
name = "hand_landmarker_subgraph",
|
name = "hand_landmarks_detector_graph",
|
||||||
srcs = ["hand_landmarker_subgraph.cc"],
|
srcs = ["hand_landmarks_detector_graph.cc"],
|
||||||
deps = [
|
deps = [
|
||||||
"//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarker_subgraph_options_cc_proto",
|
"//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarks_detector_graph_options_cc_proto",
|
||||||
"@com_google_absl//absl/status",
|
"@com_google_absl//absl/status",
|
||||||
"@com_google_absl//absl/status:statusor",
|
"@com_google_absl//absl/status:statusor",
|
||||||
"//mediapipe/calculators/core:split_vector_calculator",
|
"//mediapipe/calculators/core:split_vector_calculator",
|
||||||
|
@ -72,7 +72,7 @@ cc_library(
|
||||||
name = "hand_landmarker_graph",
|
name = "hand_landmarker_graph",
|
||||||
srcs = ["hand_landmarker_graph.cc"],
|
srcs = ["hand_landmarker_graph.cc"],
|
||||||
deps = [
|
deps = [
|
||||||
":hand_landmarker_subgraph",
|
":hand_landmarks_detector_graph",
|
||||||
"//mediapipe/calculators/core:begin_loop_calculator",
|
"//mediapipe/calculators/core:begin_loop_calculator",
|
||||||
"//mediapipe/calculators/core:clip_vector_size_calculator_cc_proto",
|
"//mediapipe/calculators/core:clip_vector_size_calculator_cc_proto",
|
||||||
"//mediapipe/calculators/core:end_loop_calculator",
|
"//mediapipe/calculators/core:end_loop_calculator",
|
||||||
|
@ -99,7 +99,7 @@ cc_library(
|
||||||
"//mediapipe/tasks/cc/vision/hand_landmarker/calculators:hand_association_calculator",
|
"//mediapipe/tasks/cc/vision/hand_landmarker/calculators:hand_association_calculator",
|
||||||
"//mediapipe/tasks/cc/vision/hand_landmarker/calculators:hand_association_calculator_cc_proto",
|
"//mediapipe/tasks/cc/vision/hand_landmarker/calculators:hand_association_calculator_cc_proto",
|
||||||
"//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarker_graph_options_cc_proto",
|
"//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarker_graph_options_cc_proto",
|
||||||
"//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarker_subgraph_options_cc_proto",
|
"//mediapipe/tasks/cc/vision/hand_landmarker/proto:hand_landmarks_detector_graph_options_cc_proto",
|
||||||
],
|
],
|
||||||
alwayslink = 1,
|
alwayslink = 1,
|
||||||
)
|
)
|
||||||
|
|
|
@ -36,7 +36,7 @@ limitations under the License.
|
||||||
#include "mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_landmarker/calculators/hand_association_calculator.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_subgraph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options.pb.h"
|
||||||
|
|
||||||
namespace mediapipe {
|
namespace mediapipe {
|
||||||
namespace tasks {
|
namespace tasks {
|
||||||
|
@ -55,7 +55,7 @@ using ::mediapipe::tasks::vision::hand_detector::proto::
|
||||||
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
||||||
HandLandmarkerGraphOptions;
|
HandLandmarkerGraphOptions;
|
||||||
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
||||||
HandLandmarkerSubgraphOptions;
|
HandLandmarksDetectorGraphOptions;
|
||||||
|
|
||||||
constexpr char kImageTag[] = "IMAGE";
|
constexpr char kImageTag[] = "IMAGE";
|
||||||
constexpr char kLandmarksTag[] = "LANDMARKS";
|
constexpr char kLandmarksTag[] = "LANDMARKS";
|
||||||
|
@ -78,14 +78,14 @@ struct HandLandmarkerOutputs {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// A "mediapipe.tasks.vision.HandLandmarkerGraph" performs hand
|
// A "mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph" performs hand
|
||||||
// landmarks detection. The HandLandmarkerGraph consists of two subgraphs:
|
// landmarks detection. The HandLandmarkerGraph consists of two subgraphs:
|
||||||
// HandDetectorGraph and HandLandmarkerSubgraph. HandLandmarkerSubgraph detects
|
// HandDetectorGraph and MultipleHandLandmarksDetectorGraph.
|
||||||
// landmarks from bounding boxes produced by HandDetectorGraph.
|
// MultipleHandLandmarksDetectorGraph detects landmarks from bounding boxes
|
||||||
// HandLandmarkerGraph tracks the landmarks over time, and skips the
|
// produced by HandDetectorGraph. HandLandmarkerGraph tracks the landmarks over
|
||||||
// HandDetectorGraph. If the tracking is lost or the detectd hands are
|
// time, and skips the HandDetectorGraph. If the tracking is lost or the detectd
|
||||||
// less than configured max number hands, HandDetectorGraph would be triggered
|
// hands are less than configured max number hands, HandDetectorGraph would be
|
||||||
// to detect hands.
|
// triggered to detect hands.
|
||||||
//
|
//
|
||||||
// Accepts CPU input images and outputs Landmarks on CPU.
|
// Accepts CPU input images and outputs Landmarks on CPU.
|
||||||
//
|
//
|
||||||
|
@ -113,7 +113,7 @@ struct HandLandmarkerOutputs {
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// node {
|
// node {
|
||||||
// calculator: "mediapipe.tasks.vision.HandLandmarkerGraph"
|
// calculator: "mediapipe.tasks.vision.hand_landmarker.HandLandmarkerGraph"
|
||||||
// input_stream: "IMAGE:image_in"
|
// input_stream: "IMAGE:image_in"
|
||||||
// output_stream: "LANDMARKS:hand_landmarks"
|
// output_stream: "LANDMARKS:hand_landmarks"
|
||||||
// output_stream: "WORLD_LANDMARKS:world_hand_landmarks"
|
// output_stream: "WORLD_LANDMARKS:world_hand_landmarks"
|
||||||
|
@ -138,7 +138,7 @@ struct HandLandmarkerOutputs {
|
||||||
// min_detection_confidence: 0.5
|
// min_detection_confidence: 0.5
|
||||||
// num_hands: 2
|
// num_hands: 2
|
||||||
// }
|
// }
|
||||||
// hand_landmarker_subgraph_options {
|
// hand_landmarks_detector_graph_options {
|
||||||
// base_options {
|
// base_options {
|
||||||
// model_asset {
|
// model_asset {
|
||||||
// file_name: "hand_landmark_lite.tflite"
|
// file_name: "hand_landmark_lite.tflite"
|
||||||
|
@ -238,15 +238,17 @@ class HandLandmarkerGraph : public core::ModelTaskGraph {
|
||||||
hand_rects >> clip_hand_rects.In("");
|
hand_rects >> clip_hand_rects.In("");
|
||||||
auto clipped_hand_rects = clip_hand_rects.Out("");
|
auto clipped_hand_rects = clip_hand_rects.Out("");
|
||||||
|
|
||||||
auto& hand_landmarker_subgraph = graph.AddNode(
|
auto& hand_landmarks_detector_graph = graph.AddNode(
|
||||||
"mediapipe.tasks.vision.hand_landmarker.HandLandmarkerSubgraph");
|
"mediapipe.tasks.vision.hand_landmarker."
|
||||||
hand_landmarker_subgraph.GetOptions<HandLandmarkerSubgraphOptions>()
|
"MultipleHandLandmarksDetectorGraph");
|
||||||
.CopyFrom(tasks_options.hand_landmarker_subgraph_options());
|
hand_landmarks_detector_graph
|
||||||
image_in >> hand_landmarker_subgraph.In("IMAGE");
|
.GetOptions<HandLandmarksDetectorGraphOptions>()
|
||||||
clipped_hand_rects >> hand_landmarker_subgraph.In("HAND_RECT");
|
.CopyFrom(tasks_options.hand_landmarks_detector_graph_options());
|
||||||
|
image_in >> hand_landmarks_detector_graph.In("IMAGE");
|
||||||
|
clipped_hand_rects >> hand_landmarks_detector_graph.In("HAND_RECT");
|
||||||
|
|
||||||
auto hand_rects_for_next_frame =
|
auto hand_rects_for_next_frame =
|
||||||
hand_landmarker_subgraph[Output<std::vector<NormalizedRect>>(
|
hand_landmarks_detector_graph[Output<std::vector<NormalizedRect>>(
|
||||||
kHandRectNextFrameTag)];
|
kHandRectNextFrameTag)];
|
||||||
// Back edge.
|
// Back edge.
|
||||||
hand_rects_for_next_frame >> previous_loopback.In("LOOP");
|
hand_rects_for_next_frame >> previous_loopback.In("LOOP");
|
||||||
|
@ -257,13 +259,13 @@ class HandLandmarkerGraph : public core::ModelTaskGraph {
|
||||||
image_in >> pass_through.In("");
|
image_in >> pass_through.In("");
|
||||||
|
|
||||||
return {{
|
return {{
|
||||||
/* landmark_lists= */ hand_landmarker_subgraph
|
/* landmark_lists= */ hand_landmarks_detector_graph
|
||||||
[Output<std::vector<NormalizedLandmarkList>>(kLandmarksTag)],
|
[Output<std::vector<NormalizedLandmarkList>>(kLandmarksTag)],
|
||||||
/* world_landmark_lists= */
|
/* world_landmark_lists= */
|
||||||
hand_landmarker_subgraph[Output<std::vector<LandmarkList>>(
|
hand_landmarks_detector_graph[Output<std::vector<LandmarkList>>(
|
||||||
kWorldLandmarksTag)],
|
kWorldLandmarksTag)],
|
||||||
/* hand_rects_next_frame= */ hand_rects_for_next_frame,
|
/* hand_rects_next_frame= */ hand_rects_for_next_frame,
|
||||||
hand_landmarker_subgraph[Output<std::vector<ClassificationList>>(
|
hand_landmarks_detector_graph[Output<std::vector<ClassificationList>>(
|
||||||
kHandednessTag)],
|
kHandednessTag)],
|
||||||
/* palm_rects= */
|
/* palm_rects= */
|
||||||
hand_detector[Output<std::vector<NormalizedRect>>(kPalmRectsTag)],
|
hand_detector[Output<std::vector<NormalizedRect>>(kPalmRectsTag)],
|
||||||
|
|
|
@ -38,7 +38,7 @@ limitations under the License.
|
||||||
#include "mediapipe/tasks/cc/core/task_runner.h"
|
#include "mediapipe/tasks/cc/core/task_runner.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_graph_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_subgraph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/utils/image_utils.h"
|
#include "mediapipe/tasks/cc/vision/utils/image_utils.h"
|
||||||
#include "tensorflow/lite/c/common.h"
|
#include "tensorflow/lite/c/common.h"
|
||||||
#include "tensorflow/lite/core/shims/cc/shims_test_util.h"
|
#include "tensorflow/lite/core/shims/cc/shims_test_util.h"
|
||||||
|
@ -111,7 +111,7 @@ absl::StatusOr<std::unique_ptr<TaskRunner>> CreateTaskRunner() {
|
||||||
->set_file_name(JoinPath("./", kTestDataDirectory, kPalmDetectionModel));
|
->set_file_name(JoinPath("./", kTestDataDirectory, kPalmDetectionModel));
|
||||||
options.mutable_hand_detector_graph_options()->mutable_base_options();
|
options.mutable_hand_detector_graph_options()->mutable_base_options();
|
||||||
options.mutable_hand_detector_graph_options()->set_num_hands(kMaxNumHands);
|
options.mutable_hand_detector_graph_options()->set_num_hands(kMaxNumHands);
|
||||||
options.mutable_hand_landmarker_subgraph_options()
|
options.mutable_hand_landmarks_detector_graph_options()
|
||||||
->mutable_base_options()
|
->mutable_base_options()
|
||||||
->mutable_model_asset()
|
->mutable_model_asset()
|
||||||
->set_file_name(
|
->set_file_name(
|
||||||
|
|
|
@ -40,7 +40,7 @@ limitations under the License.
|
||||||
#include "mediapipe/tasks/cc/core/proto/inference_subgraph.pb.h"
|
#include "mediapipe/tasks/cc/core/proto/inference_subgraph.pb.h"
|
||||||
#include "mediapipe/tasks/cc/core/utils.h"
|
#include "mediapipe/tasks/cc/core/utils.h"
|
||||||
#include "mediapipe/tasks/cc/metadata/metadata_extractor.h"
|
#include "mediapipe/tasks/cc/metadata/metadata_extractor.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_subgraph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/utils/image_tensor_specs.h"
|
#include "mediapipe/tasks/cc/vision/utils/image_tensor_specs.h"
|
||||||
#include "mediapipe/tasks/metadata/metadata_schema_generated.h"
|
#include "mediapipe/tasks/metadata/metadata_schema_generated.h"
|
||||||
#include "mediapipe/util/label_map.pb.h"
|
#include "mediapipe/util/label_map.pb.h"
|
||||||
|
@ -60,7 +60,7 @@ using ::mediapipe::api2::builder::Source;
|
||||||
using ::mediapipe::tasks::components::utils::AllowIf;
|
using ::mediapipe::tasks::components::utils::AllowIf;
|
||||||
using ::mediapipe::tasks::core::ModelResources;
|
using ::mediapipe::tasks::core::ModelResources;
|
||||||
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
||||||
HandLandmarkerSubgraphOptions;
|
HandLandmarksDetectorGraphOptions;
|
||||||
using LabelItems = mediapipe::proto_ns::Map<int64, ::mediapipe::LabelMapItem>;
|
using LabelItems = mediapipe::proto_ns::Map<int64, ::mediapipe::LabelMapItem>;
|
||||||
|
|
||||||
constexpr char kImageTag[] = "IMAGE";
|
constexpr char kImageTag[] = "IMAGE";
|
||||||
|
@ -96,7 +96,8 @@ struct HandLandmarkerOutputs {
|
||||||
Source<std::vector<ClassificationList>> handednesses;
|
Source<std::vector<ClassificationList>> handednesses;
|
||||||
};
|
};
|
||||||
|
|
||||||
absl::Status SanityCheckOptions(const HandLandmarkerSubgraphOptions& options) {
|
absl::Status SanityCheckOptions(
|
||||||
|
const HandLandmarksDetectorGraphOptions& options) {
|
||||||
if (options.min_detection_confidence() < 0 ||
|
if (options.min_detection_confidence() < 0 ||
|
||||||
options.min_detection_confidence() > 1) {
|
options.min_detection_confidence() > 1) {
|
||||||
return CreateStatusWithPayload(absl::StatusCode::kInvalidArgument,
|
return CreateStatusWithPayload(absl::StatusCode::kInvalidArgument,
|
||||||
|
@ -183,8 +184,8 @@ void ConfigureHandRectTransformationCalculator(
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
// A "mediapipe.tasks.vision.SingleHandLandmarkerSubgraph" performs hand
|
// A "mediapipe.tasks.vision.hand_landmarker.SingleHandLandmarksDetectorGraph"
|
||||||
// landmark detection.
|
// performs hand landmarks detection.
|
||||||
// - Accepts CPU input images and outputs Landmark on CPU.
|
// - Accepts CPU input images and outputs Landmark on CPU.
|
||||||
//
|
//
|
||||||
// Inputs:
|
// Inputs:
|
||||||
|
@ -212,7 +213,8 @@ void ConfigureHandRectTransformationCalculator(
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// node {
|
// node {
|
||||||
// calculator: "mediapipe.tasks.vision.SingleHandLandmarkerSubgraph"
|
// calculator:
|
||||||
|
// "mediapipe.tasks.vision.hand_landmarker.SingleHandLandmarksDetectorGraph"
|
||||||
// input_stream: "IMAGE:input_image"
|
// input_stream: "IMAGE:input_image"
|
||||||
// input_stream: "HAND_RECT:hand_rect"
|
// input_stream: "HAND_RECT:hand_rect"
|
||||||
// output_stream: "LANDMARKS:hand_landmarks"
|
// output_stream: "LANDMARKS:hand_landmarks"
|
||||||
|
@ -221,7 +223,7 @@ void ConfigureHandRectTransformationCalculator(
|
||||||
// output_stream: "PRESENCE:hand_presence"
|
// output_stream: "PRESENCE:hand_presence"
|
||||||
// output_stream: "PRESENCE_SCORE:hand_presence_score"
|
// output_stream: "PRESENCE_SCORE:hand_presence_score"
|
||||||
// options {
|
// options {
|
||||||
// [mediapipe.tasks.vision.hand_landmarker.proto.HandLandmarkerSubgraphOptions.ext]
|
// [mediapipe.tasks.vision.hand_landmarker.proto.HandLandmarksDetectorGraphOptions.ext]
|
||||||
// {
|
// {
|
||||||
// base_options {
|
// base_options {
|
||||||
// model_asset {
|
// model_asset {
|
||||||
|
@ -232,16 +234,17 @@ void ConfigureHandRectTransformationCalculator(
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
class SingleHandLandmarkerSubgraph : public core::ModelTaskGraph {
|
class SingleHandLandmarksDetectorGraph : public core::ModelTaskGraph {
|
||||||
public:
|
public:
|
||||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||||
SubgraphContext* sc) override {
|
SubgraphContext* sc) override {
|
||||||
ASSIGN_OR_RETURN(const auto* model_resources,
|
ASSIGN_OR_RETURN(
|
||||||
CreateModelResources<HandLandmarkerSubgraphOptions>(sc));
|
const auto* model_resources,
|
||||||
|
CreateModelResources<HandLandmarksDetectorGraphOptions>(sc));
|
||||||
Graph graph;
|
Graph graph;
|
||||||
ASSIGN_OR_RETURN(auto hand_landmark_detection_outs,
|
ASSIGN_OR_RETURN(auto hand_landmark_detection_outs,
|
||||||
BuildSingleHandLandmarkerSubgraph(
|
BuildSingleHandLandmarksDetectorGraph(
|
||||||
sc->Options<HandLandmarkerSubgraphOptions>(),
|
sc->Options<HandLandmarksDetectorGraphOptions>(),
|
||||||
*model_resources, graph[Input<Image>(kImageTag)],
|
*model_resources, graph[Input<Image>(kImageTag)],
|
||||||
graph[Input<NormalizedRect>(kHandRectTag)], graph));
|
graph[Input<NormalizedRect>(kHandRectTag)], graph));
|
||||||
hand_landmark_detection_outs.hand_landmarks >>
|
hand_landmark_detection_outs.hand_landmarks >>
|
||||||
|
@ -264,14 +267,16 @@ class SingleHandLandmarkerSubgraph : public core::ModelTaskGraph {
|
||||||
// Adds a mediapipe hand landmark detection graph into the provided
|
// Adds a mediapipe hand landmark detection graph into the provided
|
||||||
// builder::Graph instance.
|
// builder::Graph instance.
|
||||||
//
|
//
|
||||||
// subgraph_options: the mediapipe tasks module HandLandmarkerSubgraphOptions.
|
// subgraph_options: the mediapipe tasks module
|
||||||
// model_resources: the ModelSources object initialized from a hand landmark
|
// HandLandmarksDetectorGraphOptions. model_resources: the ModelSources object
|
||||||
|
// initialized from a hand landmark
|
||||||
// detection model file with model metadata.
|
// detection model file with model metadata.
|
||||||
// image_in: (mediapipe::Image) stream to run hand landmark detection on.
|
// image_in: (mediapipe::Image) stream to run hand landmark detection on.
|
||||||
// rect: (NormalizedRect) stream to run on the RoI of image.
|
// rect: (NormalizedRect) stream to run on the RoI of image.
|
||||||
// graph: the mediapipe graph instance to be updated.
|
// graph: the mediapipe graph instance to be updated.
|
||||||
absl::StatusOr<SingleHandLandmarkerOutputs> BuildSingleHandLandmarkerSubgraph(
|
absl::StatusOr<SingleHandLandmarkerOutputs>
|
||||||
const HandLandmarkerSubgraphOptions& subgraph_options,
|
BuildSingleHandLandmarksDetectorGraph(
|
||||||
|
const HandLandmarksDetectorGraphOptions& subgraph_options,
|
||||||
const core::ModelResources& model_resources, Source<Image> image_in,
|
const core::ModelResources& model_resources, Source<Image> image_in,
|
||||||
Source<NormalizedRect> hand_rect, Graph& graph) {
|
Source<NormalizedRect> hand_rect, Graph& graph) {
|
||||||
MP_RETURN_IF_ERROR(SanityCheckOptions(subgraph_options));
|
MP_RETURN_IF_ERROR(SanityCheckOptions(subgraph_options));
|
||||||
|
@ -415,11 +420,13 @@ class SingleHandLandmarkerSubgraph : public core::ModelTaskGraph {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
REGISTER_MEDIAPIPE_GRAPH(
|
REGISTER_MEDIAPIPE_GRAPH(
|
||||||
::mediapipe::tasks::vision::hand_landmarker::SingleHandLandmarkerSubgraph);
|
::mediapipe::tasks::vision::hand_landmarker::SingleHandLandmarksDetectorGraph); // NOLINT
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
// A "mediapipe.tasks.vision.HandLandmarkerSubgraph" performs multi hand
|
// A "mediapipe.tasks.vision.hand_landmarker.MultipleHandLandmarksDetectorGraph"
|
||||||
// landmark detection.
|
// performs multi hand landmark detection.
|
||||||
// - Accepts CPU input image and a vector of hand rect RoIs to detect the
|
// - Accepts CPU input image and a vector of hand rect RoIs to detect the
|
||||||
// multiple hands landmarks enclosed by the RoIs. Output vectors of
|
// multiple hands landmarks enclosed by the RoIs. Output vectors of
|
||||||
// hand landmarks related results, where each element in the vectors
|
// hand landmarks related results, where each element in the vectors
|
||||||
|
@ -450,7 +457,8 @@ REGISTER_MEDIAPIPE_GRAPH(
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
// node {
|
// node {
|
||||||
// calculator: "mediapipe.tasks.vision.HandLandmarkerSubgraph"
|
// calculator:
|
||||||
|
// "mediapipe.tasks.vision.hand_landmarker.MultipleHandLandmarksDetectorGraph"
|
||||||
// input_stream: "IMAGE:input_image"
|
// input_stream: "IMAGE:input_image"
|
||||||
// input_stream: "HAND_RECT:hand_rect"
|
// input_stream: "HAND_RECT:hand_rect"
|
||||||
// output_stream: "LANDMARKS:hand_landmarks"
|
// output_stream: "LANDMARKS:hand_landmarks"
|
||||||
|
@ -460,7 +468,7 @@ REGISTER_MEDIAPIPE_GRAPH(
|
||||||
// output_stream: "PRESENCE_SCORE:hand_presence_score"
|
// output_stream: "PRESENCE_SCORE:hand_presence_score"
|
||||||
// output_stream: "HANDEDNESS:handedness"
|
// output_stream: "HANDEDNESS:handedness"
|
||||||
// options {
|
// options {
|
||||||
// [mediapipe.tasks.vision.hand_landmarker.proto.HandLandmarkerSubgraphOptions.ext]
|
// [mediapipe.tasks.vision.hand_landmarker.proto.HandLandmarksDetectorGraphOptions.ext]
|
||||||
// {
|
// {
|
||||||
// base_options {
|
// base_options {
|
||||||
// model_asset {
|
// model_asset {
|
||||||
|
@ -471,15 +479,15 @@ REGISTER_MEDIAPIPE_GRAPH(
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
class HandLandmarkerSubgraph : public core::ModelTaskGraph {
|
class MultipleHandLandmarksDetectorGraph : public core::ModelTaskGraph {
|
||||||
public:
|
public:
|
||||||
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
absl::StatusOr<CalculatorGraphConfig> GetConfig(
|
||||||
SubgraphContext* sc) override {
|
SubgraphContext* sc) override {
|
||||||
Graph graph;
|
Graph graph;
|
||||||
ASSIGN_OR_RETURN(
|
ASSIGN_OR_RETURN(
|
||||||
auto hand_landmark_detection_outputs,
|
auto hand_landmark_detection_outputs,
|
||||||
BuildHandLandmarkerSubgraph(
|
BuildHandLandmarksDetectorGraph(
|
||||||
sc->Options<HandLandmarkerSubgraphOptions>(),
|
sc->Options<HandLandmarksDetectorGraphOptions>(),
|
||||||
graph[Input<Image>(kImageTag)],
|
graph[Input<Image>(kImageTag)],
|
||||||
graph[Input<std::vector<NormalizedRect>>(kHandRectTag)], graph));
|
graph[Input<std::vector<NormalizedRect>>(kHandRectTag)], graph));
|
||||||
hand_landmark_detection_outputs.landmark_lists >>
|
hand_landmark_detection_outputs.landmark_lists >>
|
||||||
|
@ -499,14 +507,15 @@ class HandLandmarkerSubgraph : public core::ModelTaskGraph {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
absl::StatusOr<HandLandmarkerOutputs> BuildHandLandmarkerSubgraph(
|
absl::StatusOr<HandLandmarkerOutputs> BuildHandLandmarksDetectorGraph(
|
||||||
const HandLandmarkerSubgraphOptions& subgraph_options,
|
const HandLandmarksDetectorGraphOptions& subgraph_options,
|
||||||
Source<Image> image_in,
|
Source<Image> image_in,
|
||||||
Source<std::vector<NormalizedRect>> multi_hand_rects, Graph& graph) {
|
Source<std::vector<NormalizedRect>> multi_hand_rects, Graph& graph) {
|
||||||
auto& hand_landmark_subgraph = graph.AddNode(
|
auto& hand_landmark_subgraph = graph.AddNode(
|
||||||
"mediapipe.tasks.vision.hand_landmarker.SingleHandLandmarkerSubgraph");
|
"mediapipe.tasks.vision.hand_landmarker."
|
||||||
hand_landmark_subgraph.GetOptions<HandLandmarkerSubgraphOptions>().CopyFrom(
|
"SingleHandLandmarksDetectorGraph");
|
||||||
subgraph_options);
|
hand_landmark_subgraph.GetOptions<HandLandmarksDetectorGraphOptions>()
|
||||||
|
.CopyFrom(subgraph_options);
|
||||||
|
|
||||||
auto& begin_loop_multi_hand_rects =
|
auto& begin_loop_multi_hand_rects =
|
||||||
graph.AddNode("BeginLoopNormalizedRectCalculator");
|
graph.AddNode("BeginLoopNormalizedRectCalculator");
|
||||||
|
@ -580,8 +589,10 @@ class HandLandmarkerSubgraph : public core::ModelTaskGraph {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
REGISTER_MEDIAPIPE_GRAPH(
|
REGISTER_MEDIAPIPE_GRAPH(
|
||||||
::mediapipe::tasks::vision::hand_landmarker::HandLandmarkerSubgraph);
|
::mediapipe::tasks::vision::hand_landmarker::MultipleHandLandmarksDetectorGraph); // NOLINT
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
} // namespace hand_landmarker
|
} // namespace hand_landmarker
|
||||||
} // namespace vision
|
} // namespace vision
|
|
@ -39,7 +39,7 @@ limitations under the License.
|
||||||
#include "mediapipe/tasks/cc/core/proto/base_options.pb.h"
|
#include "mediapipe/tasks/cc/core/proto/base_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/core/proto/external_file.pb.h"
|
#include "mediapipe/tasks/cc/core/proto/external_file.pb.h"
|
||||||
#include "mediapipe/tasks/cc/core/task_runner.h"
|
#include "mediapipe/tasks/cc/core/task_runner.h"
|
||||||
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_subgraph_options.pb.h"
|
#include "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options.pb.h"
|
||||||
#include "mediapipe/tasks/cc/vision/utils/image_utils.h"
|
#include "mediapipe/tasks/cc/vision/utils/image_utils.h"
|
||||||
|
|
||||||
namespace mediapipe {
|
namespace mediapipe {
|
||||||
|
@ -58,7 +58,7 @@ using ::mediapipe::file::JoinPath;
|
||||||
using ::mediapipe::tasks::core::TaskRunner;
|
using ::mediapipe::tasks::core::TaskRunner;
|
||||||
using ::mediapipe::tasks::vision::DecodeImageFromFile;
|
using ::mediapipe::tasks::vision::DecodeImageFromFile;
|
||||||
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
using ::mediapipe::tasks::vision::hand_landmarker::proto::
|
||||||
HandLandmarkerSubgraphOptions;
|
HandLandmarksDetectorGraphOptions;
|
||||||
using ::testing::ElementsAreArray;
|
using ::testing::ElementsAreArray;
|
||||||
using ::testing::EqualsProto;
|
using ::testing::EqualsProto;
|
||||||
using ::testing::Pointwise;
|
using ::testing::Pointwise;
|
||||||
|
@ -114,12 +114,13 @@ absl::StatusOr<std::unique_ptr<TaskRunner>> CreateSingleHandTaskRunner(
|
||||||
Graph graph;
|
Graph graph;
|
||||||
|
|
||||||
auto& hand_landmark_detection = graph.AddNode(
|
auto& hand_landmark_detection = graph.AddNode(
|
||||||
"mediapipe.tasks.vision.hand_landmarker.SingleHandLandmarkerSubgraph");
|
"mediapipe.tasks.vision.hand_landmarker."
|
||||||
|
"SingleHandLandmarksDetectorGraph");
|
||||||
|
|
||||||
auto options = std::make_unique<HandLandmarkerSubgraphOptions>();
|
auto options = std::make_unique<HandLandmarksDetectorGraphOptions>();
|
||||||
options->mutable_base_options()->mutable_model_asset()->set_file_name(
|
options->mutable_base_options()->mutable_model_asset()->set_file_name(
|
||||||
JoinPath("./", kTestDataDirectory, model_name));
|
JoinPath("./", kTestDataDirectory, model_name));
|
||||||
hand_landmark_detection.GetOptions<HandLandmarkerSubgraphOptions>().Swap(
|
hand_landmark_detection.GetOptions<HandLandmarksDetectorGraphOptions>().Swap(
|
||||||
options.get());
|
options.get());
|
||||||
|
|
||||||
graph[Input<Image>(kImageTag)].SetName(kImageName) >>
|
graph[Input<Image>(kImageTag)].SetName(kImageName) >>
|
||||||
|
@ -153,12 +154,13 @@ absl::StatusOr<std::unique_ptr<TaskRunner>> CreateMultiHandTaskRunner(
|
||||||
Graph graph;
|
Graph graph;
|
||||||
|
|
||||||
auto& multi_hand_landmark_detection = graph.AddNode(
|
auto& multi_hand_landmark_detection = graph.AddNode(
|
||||||
"mediapipe.tasks.vision.hand_landmarker.HandLandmarkerSubgraph");
|
"mediapipe.tasks.vision.hand_landmarker."
|
||||||
|
"MultipleHandLandmarksDetectorGraph");
|
||||||
|
|
||||||
auto options = std::make_unique<HandLandmarkerSubgraphOptions>();
|
auto options = std::make_unique<HandLandmarksDetectorGraphOptions>();
|
||||||
options->mutable_base_options()->mutable_model_asset()->set_file_name(
|
options->mutable_base_options()->mutable_model_asset()->set_file_name(
|
||||||
JoinPath("./", kTestDataDirectory, model_name));
|
JoinPath("./", kTestDataDirectory, model_name));
|
||||||
multi_hand_landmark_detection.GetOptions<HandLandmarkerSubgraphOptions>()
|
multi_hand_landmark_detection.GetOptions<HandLandmarksDetectorGraphOptions>()
|
||||||
.Swap(options.get());
|
.Swap(options.get());
|
||||||
|
|
||||||
graph[Input<Image>(kImageTag)].SetName(kImageName) >>
|
graph[Input<Image>(kImageTag)].SetName(kImageName) >>
|
|
@ -21,8 +21,8 @@ package(default_visibility = [
|
||||||
licenses(["notice"])
|
licenses(["notice"])
|
||||||
|
|
||||||
mediapipe_proto_library(
|
mediapipe_proto_library(
|
||||||
name = "hand_landmarker_subgraph_options_proto",
|
name = "hand_landmarks_detector_graph_options_proto",
|
||||||
srcs = ["hand_landmarker_subgraph_options.proto"],
|
srcs = ["hand_landmarks_detector_graph_options.proto"],
|
||||||
deps = [
|
deps = [
|
||||||
"//mediapipe/framework:calculator_options_proto",
|
"//mediapipe/framework:calculator_options_proto",
|
||||||
"//mediapipe/framework:calculator_proto",
|
"//mediapipe/framework:calculator_proto",
|
||||||
|
@ -34,7 +34,7 @@ mediapipe_proto_library(
|
||||||
name = "hand_landmarker_graph_options_proto",
|
name = "hand_landmarker_graph_options_proto",
|
||||||
srcs = ["hand_landmarker_graph_options.proto"],
|
srcs = ["hand_landmarker_graph_options.proto"],
|
||||||
deps = [
|
deps = [
|
||||||
":hand_landmarker_subgraph_options_proto",
|
":hand_landmarks_detector_graph_options_proto",
|
||||||
"//mediapipe/framework:calculator_options_proto",
|
"//mediapipe/framework:calculator_options_proto",
|
||||||
"//mediapipe/framework:calculator_proto",
|
"//mediapipe/framework:calculator_proto",
|
||||||
"//mediapipe/tasks/cc/core/proto:base_options_proto",
|
"//mediapipe/tasks/cc/core/proto:base_options_proto",
|
||||||
|
|
|
@ -20,7 +20,7 @@ package mediapipe.tasks.vision.hand_landmarker.proto;
|
||||||
import "mediapipe/framework/calculator.proto";
|
import "mediapipe/framework/calculator.proto";
|
||||||
import "mediapipe/tasks/cc/core/proto/base_options.proto";
|
import "mediapipe/tasks/cc/core/proto/base_options.proto";
|
||||||
import "mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options.proto";
|
import "mediapipe/tasks/cc/vision/hand_detector/proto/hand_detector_graph_options.proto";
|
||||||
import "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarker_subgraph_options.proto";
|
import "mediapipe/tasks/cc/vision/hand_landmarker/proto/hand_landmarks_detector_graph_options.proto";
|
||||||
|
|
||||||
message HandLandmarkerGraphOptions {
|
message HandLandmarkerGraphOptions {
|
||||||
extend mediapipe.CalculatorOptions {
|
extend mediapipe.CalculatorOptions {
|
||||||
|
@ -35,7 +35,8 @@ message HandLandmarkerGraphOptions {
|
||||||
hand_detector_graph_options = 2;
|
hand_detector_graph_options = 2;
|
||||||
|
|
||||||
// Options for hand landmarker subgraph.
|
// Options for hand landmarker subgraph.
|
||||||
optional HandLandmarkerSubgraphOptions hand_landmarker_subgraph_options = 3;
|
optional HandLandmarksDetectorGraphOptions
|
||||||
|
hand_landmarks_detector_graph_options = 3;
|
||||||
|
|
||||||
// Minimum confidence for hand landmarks tracking to be considered
|
// Minimum confidence for hand landmarks tracking to be considered
|
||||||
// successfully.
|
// successfully.
|
||||||
|
|
|
@ -20,9 +20,9 @@ package mediapipe.tasks.vision.hand_landmarker.proto;
|
||||||
import "mediapipe/framework/calculator.proto";
|
import "mediapipe/framework/calculator.proto";
|
||||||
import "mediapipe/tasks/cc/core/proto/base_options.proto";
|
import "mediapipe/tasks/cc/core/proto/base_options.proto";
|
||||||
|
|
||||||
message HandLandmarkerSubgraphOptions {
|
message HandLandmarksDetectorGraphOptions {
|
||||||
extend mediapipe.CalculatorOptions {
|
extend mediapipe.CalculatorOptions {
|
||||||
optional HandLandmarkerSubgraphOptions ext = 474472470;
|
optional HandLandmarksDetectorGraphOptions ext = 474472470;
|
||||||
}
|
}
|
||||||
// Base options for configuring MediaPipe Tasks, such as specifying the TfLite
|
// Base options for configuring MediaPipe Tasks, such as specifying the TfLite
|
||||||
// model file with metadata, accelerator options, etc.
|
// model file with metadata, accelerator options, etc.
|
Loading…
Reference in New Issue
Block a user