landmarks_to_detection stream utility function.
PiperOrigin-RevId: 563633314
This commit is contained in:
parent
7549677408
commit
886a118232
|
@ -2,6 +2,34 @@ package(default_visibility = ["//visibility:public"])
|
|||
|
||||
licenses(["notice"])
|
||||
|
||||
cc_library(
|
||||
name = "landmarks_to_detection",
|
||||
srcs = ["landmarks_to_detection.cc"],
|
||||
hdrs = ["landmarks_to_detection.h"],
|
||||
deps = [
|
||||
"//mediapipe/calculators/util:landmarks_to_detection_calculator",
|
||||
"//mediapipe/framework/api2:builder",
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"//mediapipe/framework/formats:landmark_cc_proto",
|
||||
],
|
||||
)
|
||||
|
||||
cc_test(
|
||||
name = "landmarks_to_detection_test",
|
||||
srcs = ["landmarks_to_detection_test.cc"],
|
||||
deps = [
|
||||
":landmarks_to_detection",
|
||||
"//mediapipe/framework/api2:builder",
|
||||
"//mediapipe/framework/formats:detection_cc_proto",
|
||||
"//mediapipe/framework/formats:landmark_cc_proto",
|
||||
"//mediapipe/framework/port:gtest",
|
||||
"//mediapipe/framework/port:gtest_main",
|
||||
"//mediapipe/framework/port:parse_text_proto",
|
||||
"//mediapipe/framework/port:status",
|
||||
"//mediapipe/framework/port:status_matchers",
|
||||
],
|
||||
)
|
||||
|
||||
cc_library(
|
||||
name = "landmarks_projection",
|
||||
srcs = ["landmarks_projection.cc"],
|
||||
|
|
17
mediapipe/framework/api2/stream/landmarks_to_detection.cc
Normal file
17
mediapipe/framework/api2/stream/landmarks_to_detection.cc
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "mediapipe/framework/api2/stream/landmarks_to_detection.h"
|
||||
|
||||
#include "mediapipe/framework/api2/builder.h"
|
||||
#include "mediapipe/framework/formats/detection.pb.h"
|
||||
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||
|
||||
namespace mediapipe::api2::builder {
|
||||
|
||||
Stream<mediapipe::Detection> ConvertLandmarksToDetection(
|
||||
Stream<mediapipe::NormalizedLandmarkList> landmarks, Graph& graph) {
|
||||
auto& landmarks_to_detection =
|
||||
graph.AddNode("LandmarksToDetectionCalculator");
|
||||
landmarks.ConnectTo(landmarks_to_detection.In("NORM_LANDMARKS"));
|
||||
return landmarks_to_detection.Out("DETECTION").Cast<mediapipe::Detection>();
|
||||
}
|
||||
|
||||
} // namespace mediapipe::api2::builder
|
16
mediapipe/framework/api2/stream/landmarks_to_detection.h
Normal file
16
mediapipe/framework/api2/stream/landmarks_to_detection.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef MEDIAPIPE_FRAMEWORK_API2_STREAM_LANDMARKS_TO_DETECTION_H_
|
||||
#define MEDIAPIPE_FRAMEWORK_API2_STREAM_LANDMARKS_TO_DETECTION_H_
|
||||
|
||||
#include "mediapipe/framework/api2/builder.h"
|
||||
#include "mediapipe/framework/formats/detection.pb.h"
|
||||
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||
|
||||
namespace mediapipe::api2::builder {
|
||||
|
||||
// Updates @graph to convert @landmarks to a detection.
|
||||
Stream<mediapipe::Detection> ConvertLandmarksToDetection(
|
||||
Stream<mediapipe::NormalizedLandmarkList> landmarks, Graph& graph);
|
||||
|
||||
} // namespace mediapipe::api2::builder
|
||||
|
||||
#endif // MEDIAPIPE_FRAMEWORK_API2_STREAM_LANDMARKS_TO_DETECTION_H_
|
|
@ -0,0 +1,35 @@
|
|||
#include "mediapipe/framework/api2/stream/landmarks_to_detection.h"
|
||||
|
||||
#include "mediapipe/framework/api2/builder.h"
|
||||
#include "mediapipe/framework/formats/detection.pb.h"
|
||||
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||
#include "mediapipe/framework/port/gmock.h"
|
||||
#include "mediapipe/framework/port/gtest.h"
|
||||
#include "mediapipe/framework/port/parse_text_proto.h"
|
||||
#include "mediapipe/framework/port/status_matchers.h"
|
||||
|
||||
namespace mediapipe::api2::builder {
|
||||
namespace {
|
||||
|
||||
TEST(LandmarksToDetection, VerifyConfig) {
|
||||
mediapipe::api2::builder::Graph graph;
|
||||
|
||||
Stream<NormalizedLandmarkList> landmarks =
|
||||
graph.In("LANDMARKS").Cast<NormalizedLandmarkList>();
|
||||
Stream<Detection> detection = ConvertLandmarksToDetection(landmarks, graph);
|
||||
detection.SetName("detection");
|
||||
|
||||
EXPECT_THAT(
|
||||
graph.GetConfig(),
|
||||
EqualsProto(mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"pb(
|
||||
node {
|
||||
calculator: "LandmarksToDetectionCalculator"
|
||||
input_stream: "NORM_LANDMARKS:__stream_0"
|
||||
output_stream: "DETECTION:detection"
|
||||
}
|
||||
input_stream: "LANDMARKS:__stream_0"
|
||||
)pb")));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace mediapipe::api2::builder
|
Loading…
Reference in New Issue
Block a user