Move stream API landmarks_projection to third_party.
PiperOrigin-RevId: 563246209
This commit is contained in:
parent
7252f6f2e7
commit
a9da6d325c
|
@ -2,6 +2,33 @@ package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
licenses(["notice"])
|
licenses(["notice"])
|
||||||
|
|
||||||
|
cc_library(
|
||||||
|
name = "landmarks_projection",
|
||||||
|
srcs = ["landmarks_projection.cc"],
|
||||||
|
hdrs = ["landmarks_projection.h"],
|
||||||
|
deps = [
|
||||||
|
"//mediapipe/calculators/util:landmark_projection_calculator",
|
||||||
|
"//mediapipe/framework/api2:builder",
|
||||||
|
"//mediapipe/framework/formats:landmark_cc_proto",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
cc_test(
|
||||||
|
name = "landmarks_projection_test",
|
||||||
|
srcs = ["landmarks_projection_test.cc"],
|
||||||
|
deps = [
|
||||||
|
":landmarks_projection",
|
||||||
|
"//mediapipe/framework:calculator_framework",
|
||||||
|
"//mediapipe/framework/api2:builder",
|
||||||
|
"//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(
|
cc_library(
|
||||||
name = "loopback",
|
name = "loopback",
|
||||||
hdrs = ["loopback.h"],
|
hdrs = ["loopback.h"],
|
||||||
|
|
20
mediapipe/framework/api2/stream/landmarks_projection.cc
Normal file
20
mediapipe/framework/api2/stream/landmarks_projection.cc
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include "mediapipe/framework/api2/stream/landmarks_projection.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "mediapipe/framework/api2/builder.h"
|
||||||
|
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||||
|
|
||||||
|
namespace mediapipe::api2::builder {
|
||||||
|
|
||||||
|
Stream<mediapipe::NormalizedLandmarkList> ProjectLandmarks(
|
||||||
|
Stream<mediapipe::NormalizedLandmarkList> landmarks,
|
||||||
|
Stream<std::array<float, 16>> projection_matrix, Graph& graph) {
|
||||||
|
auto& projector = graph.AddNode("LandmarkProjectionCalculator");
|
||||||
|
landmarks.ConnectTo(projector.In("NORM_LANDMARKS"));
|
||||||
|
projection_matrix.ConnectTo(projector.In("PROJECTION_MATRIX"));
|
||||||
|
return projector.Out("NORM_LANDMARKS")
|
||||||
|
.Cast<mediapipe::NormalizedLandmarkList>();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mediapipe::api2::builder
|
23
mediapipe/framework/api2/stream/landmarks_projection.h
Normal file
23
mediapipe/framework/api2/stream/landmarks_projection.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef MEDIAPIPE_FRAMEWORK_API2_STREAM_LANDMARKS_PROJECTION_H_
|
||||||
|
#define MEDIAPIPE_FRAMEWORK_API2_STREAM_LANDMARKS_PROJECTION_H_
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "mediapipe/framework/api2/builder.h"
|
||||||
|
#include "mediapipe/framework/formats/landmark.pb.h"
|
||||||
|
|
||||||
|
namespace mediapipe::api2::builder {
|
||||||
|
|
||||||
|
// Updates @graph to project predicted @landmarks back to the original @image
|
||||||
|
// based on @projection_matrix
|
||||||
|
//
|
||||||
|
// @landmarks - landmarks (NormalizedLandmarkList) stream, output from the model
|
||||||
|
// @projection_matrix - matrix that stores the preprocessing information
|
||||||
|
// @graph - mediapipe graph to update.
|
||||||
|
Stream<mediapipe::NormalizedLandmarkList> ProjectLandmarks(
|
||||||
|
Stream<mediapipe::NormalizedLandmarkList> landmarks,
|
||||||
|
Stream<std::array<float, 16>> projection_matrix, Graph& graph);
|
||||||
|
|
||||||
|
} // namespace mediapipe::api2::builder
|
||||||
|
|
||||||
|
#endif // MEDIAPIPE_FRAMEWORK_API2_STREAM_LANDMARKS_PROJECTION_H_
|
45
mediapipe/framework/api2/stream/landmarks_projection_test.cc
Normal file
45
mediapipe/framework/api2/stream/landmarks_projection_test.cc
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#include "mediapipe/framework/api2/stream/landmarks_projection.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
|
||||||
|
#include "mediapipe/framework/api2/builder.h"
|
||||||
|
#include "mediapipe/framework/calculator_framework.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(LandmarksProjection, ProjectLandmarks) {
|
||||||
|
mediapipe::api2::builder::Graph graph;
|
||||||
|
|
||||||
|
Stream<NormalizedLandmarkList> landmarks =
|
||||||
|
graph.In("NORM_LANDMARKS").Cast<NormalizedLandmarkList>();
|
||||||
|
Stream<std::array<float, 16>> projection_matrix =
|
||||||
|
graph.In("PROJECTION_MATRIX").Cast<std::array<float, 16>>();
|
||||||
|
Stream<NormalizedLandmarkList> result =
|
||||||
|
ProjectLandmarks(landmarks, projection_matrix, graph);
|
||||||
|
result.SetName("landmarks_value");
|
||||||
|
|
||||||
|
EXPECT_THAT(
|
||||||
|
graph.GetConfig(),
|
||||||
|
EqualsProto(mediapipe::ParseTextProtoOrDie<CalculatorGraphConfig>(R"pb(
|
||||||
|
node {
|
||||||
|
calculator: "LandmarkProjectionCalculator"
|
||||||
|
input_stream: "NORM_LANDMARKS:__stream_0"
|
||||||
|
input_stream: "PROJECTION_MATRIX:__stream_1"
|
||||||
|
output_stream: "NORM_LANDMARKS:landmarks_value"
|
||||||
|
}
|
||||||
|
input_stream: "NORM_LANDMARKS:__stream_0"
|
||||||
|
input_stream: "PROJECTION_MATRIX:__stream_1"
|
||||||
|
)pb")));
|
||||||
|
|
||||||
|
CalculatorGraph calcualtor_graph;
|
||||||
|
MP_EXPECT_OK(calcualtor_graph.Initialize(graph.GetConfig()));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace mediapipe::api2::builder
|
Loading…
Reference in New Issue
Block a user