Skip to content

Commit

Permalink
feat(sdk): implement FaceGeometryPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed May 2, 2021
1 parent da46b99 commit 473c3a0
Show file tree
Hide file tree
Showing 15 changed files with 214 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Mediapipe {
public class FaceGeometryPacket : Packet<FaceGeometry.FaceGeometry> {
public FaceGeometryPacket() : base() {}
public FaceGeometryPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) {}

public override FaceGeometry.FaceGeometry Get() {
UnsafeNativeMethods.mp_Packet__GetFaceGeometry(mpPtr, out var serializedProtoPtr).Assert();
GC.KeepAlive(this);

var geometry = Protobuf.DeserializeProto<FaceGeometry.FaceGeometry>(serializedProtoPtr, FaceGeometry.FaceGeometry.Parser);
UnsafeNativeMethods.mp_api_SerializedProto__delete(serializedProtoPtr);

return geometry;
}

public override StatusOr<FaceGeometry.FaceGeometry> Consume() {
throw new NotSupportedException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;

namespace Mediapipe {
public class FaceGeometryVectorPacket : Packet<List<FaceGeometry.FaceGeometry>> {
public FaceGeometryVectorPacket() : base() {}
public FaceGeometryVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) {}

public override List<FaceGeometry.FaceGeometry> Get() {
UnsafeNativeMethods.mp_Packet__GetFaceGeometryVector(mpPtr, out var serializedProtoVectorPtr).Assert();
GC.KeepAlive(this);

var geometries = Protobuf.DeserializeProtoVector<FaceGeometry.FaceGeometry>(serializedProtoVectorPtr, FaceGeometry.FaceGeometry.Parser);
UnsafeNativeMethods.mp_api_SerializedProtoVector__delete(serializedProtoVectorPtr);

return geometries;
}

public override StatusOr<List<FaceGeometry.FaceGeometry>> Consume() {
throw new NotSupportedException();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public static extern MpReturnCode google_protobuf__SetLogHandler__PF(

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Packet__GetTimedModelMatrixProtoList(IntPtr packet, out IntPtr serializedProto);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Packet__GetFaceGeometry(IntPtr packet, out IntPtr serializedProto);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode mp_Packet__GetFaceGeometryVector(IntPtr packet, out IntPtr serializedProto);
#endregion
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions mediapipe_api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ cc_library(
"//mediapipe_api/framework/formats:rect",
"//mediapipe_api/framework/port:logging",
"//mediapipe_api/graphs/object_detection_3d/calculators:model_matrix",
"//mediapipe_api/modules/face_geometry/protos:face_geometry",
"//mediapipe_api/util:resource_util",
] + select({
"@com_google_mediapipe//mediapipe/gpu:disable_gpu": [],
Expand Down Expand Up @@ -176,10 +177,13 @@ pkg_zip(
"//mediapipe_api/framework/formats:detection_cs",
"//mediapipe_api/framework/formats:landmark_cs",
"//mediapipe_api/framework/formats:location_data_cs",
"//mediapipe_api/framework/formats:matrix_data_cs",
"//mediapipe_api/framework/formats:rasterization_cs",
"//mediapipe_api/framework/formats:rect_cs",
"//mediapipe_api/graphs/instant_motion_tracking/calculators:sticker_buffer_cs",
"//mediapipe_api/graphs/object_detection_3d/calculators:model_matrix_cs",
"//mediapipe_api/modules/face_geometry/protos:face_geometry_cs",
"//mediapipe_api/modules/face_geometry/protos:mesh_3d_cs",
],
# TODO: keep directory structure
)
Expand Down
17 changes: 16 additions & 1 deletion mediapipe_api/csharp_proto_src.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,22 @@ mv {outdir}/{outfile} $$(dirname $(location {outfile}))
)

def _camelize(str):
return "".join([x.capitalize() for x in str.split("_")])
res = ""
need_capitalize = True

for s in str.elems():
if not s.isalnum():
need_capitalize = True
continue

if need_capitalize:
res += s.capitalize()
else:
res += s

need_capitalize = s.isdigit()

return res

def _replace_suffix(string, old, new):
"""Returns a string with an old suffix replaced by a new suffix."""
Expand Down
12 changes: 8 additions & 4 deletions mediapipe_api/framework/formats/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ csharp_proto_src(
proto_src = "mediapipe/framework/formats/classification.proto",
deps = [
"@com_google_mediapipe//mediapipe/framework/formats:protos_src",
"@com_google_mediapipe//mediapipe/framework/formats/annotation:protos_src",
],
)

Expand All @@ -93,7 +92,6 @@ csharp_proto_src(
proto_src = "mediapipe/framework/formats/landmark.proto",
deps = [
"@com_google_mediapipe//mediapipe/framework/formats:protos_src",
"@com_google_mediapipe//mediapipe/framework/formats/annotation:protos_src",
],
)

Expand All @@ -106,20 +104,26 @@ csharp_proto_src(
],
)

csharp_proto_src(
name = "matrix_data_cs",
proto_src = "mediapipe/framework/formats/matrix_data.proto",
deps = [
"@com_google_mediapipe//mediapipe/framework/formats:protos_src",
],
)

csharp_proto_src(
name = "rect_cs",
proto_src = "mediapipe/framework/formats/rect.proto",
deps = [
"@com_google_mediapipe//mediapipe/framework/formats:protos_src",
"@com_google_mediapipe//mediapipe/framework/formats/annotation:protos_src",
],
)

csharp_proto_src(
name = "rasterization_cs",
proto_src = "mediapipe/framework/formats/annotation/rasterization.proto",
deps = [
"@com_google_mediapipe//mediapipe/framework/formats:protos_src",
"@com_google_mediapipe//mediapipe/framework/formats/annotation:protos_src",
],
import_prefix = "Annotation",
Expand Down
33 changes: 33 additions & 0 deletions mediapipe_api/modules/face_geometry/protos/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
load("//mediapipe_api:csharp_proto_src.bzl", "csharp_proto_src")

package(default_visibility = ["//visibility:public"])

cc_library(
name = "face_geometry",
srcs = ["face_geometry.cc"],
hdrs = ["face_geometry.h"],
deps = [
"@com_google_mediapipe//mediapipe/modules/face_geometry/protos:face_geometry_cc_proto",
"//mediapipe_api:common",
"//mediapipe_api/external:protobuf",
"//mediapipe_api/framework:packet",
],
alwayslink = True,
)

csharp_proto_src(
name = "face_geometry_cs",
proto_src = "mediapipe/modules/face_geometry/protos/face_geometry.proto",
deps = [
"@com_google_mediapipe//mediapipe/framework/formats:protos_src",
"@com_google_mediapipe//mediapipe/modules/face_geometry/protos:protos_src",
],
)

csharp_proto_src(
name = "mesh_3d_cs",
proto_src = "mediapipe/modules/face_geometry/protos/mesh_3d.proto",
deps = [
"@com_google_mediapipe//mediapipe/modules/face_geometry/protos:protos_src",
],
)
9 changes: 9 additions & 0 deletions mediapipe_api/modules/face_geometry/protos/face_geometry.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "mediapipe_api/modules/face_geometry/protos/face_geometry.h"

MpReturnCode mp_Packet__GetFaceGeometry(mediapipe::Packet* packet, mp_api::SerializedProto** value_out) {
return mp_Packet__GetSerializedProto<mediapipe::face_geometry::FaceGeometry>(packet, value_out);
}

MpReturnCode mp_Packet__GetFaceGeometryVector(mediapipe::Packet* packet, mp_api::SerializedProtoVector** value_out) {
return mp_Packet__GetSerializedProtoVector<mediapipe::face_geometry::FaceGeometry>(packet, value_out);
}
16 changes: 16 additions & 0 deletions mediapipe_api/modules/face_geometry/protos/face_geometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef C_MEDIAPIPE_API_MODULES_FACE_GEOMETRY_PROTOS_FACE_GEOMETRY_H_
#define C_MEDIAPIPE_API_MODULES_FACE_GEOMETRY_PROTOS_FACE_GEOMETRY_H_

#include "mediapipe/modules/face_geometry/protos/face_geometry.pb.h"
#include "mediapipe_api/common.h"
#include "mediapipe_api/external/protobuf.h"
#include "mediapipe_api/framework/packet.h"

extern "C" {

MP_CAPI(MpReturnCode) mp_Packet__GetFaceGeometry(mediapipe::Packet* packet, mp_api::SerializedProto** value_out);
MP_CAPI(MpReturnCode) mp_Packet__GetFaceGeometryVector(mediapipe::Packet* packet, mp_api::SerializedProtoVector** value_out);

} // extern "C"

#endif // C_MEDIAPIPE_API_MODULES_FACE_GEOMETRY_PROTOS_FACE_GEOMETRY_H_
30 changes: 22 additions & 8 deletions third_party/mediapipe_visibility.diff
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
diff --git a/mediapipe/framework/BUILD b/mediapipe/framework/BUILD
index 7f66bdd..af77cd6 100644
index 2124ca5..d47e820 100644
--- a/mediapipe/framework/BUILD
+++ b/mediapipe/framework/BUILD
@@ -1609,5 +1609,5 @@ cc_test(
@@ -1652,5 +1652,5 @@ cc_test(
filegroup(
name = "protos_src",
srcs = glob(["*.proto"]),
- visibility = ["//mediapipe:__subpackages__"],
+ visibility = ["//visibility:public"],
)
diff --git a/mediapipe/framework/formats/BUILD b/mediapipe/framework/formats/BUILD
index dfe4329..2c1e68e 100644
index 3067eb2..434bae3 100644
--- a/mediapipe/framework/formats/BUILD
+++ b/mediapipe/framework/formats/BUILD
@@ -274,7 +274,7 @@ mediapipe_register_type(
@@ -275,7 +275,7 @@ mediapipe_register_type(
filegroup(
name = "protos_src",
srcs = glob(["*.proto"]),
Expand All @@ -34,7 +34,7 @@ index 2e33f76..4b15727 100644
+ visibility = ["//visibility:public"],
)
diff --git a/mediapipe/graphs/instant_motion_tracking/calculators/BUILD b/mediapipe/graphs/instant_motion_tracking/calculators/BUILD
index b8242cf..023ef4f 100644
index 93af68c..2ef17af 100644
--- a/mediapipe/graphs/instant_motion_tracking/calculators/BUILD
+++ b/mediapipe/graphs/instant_motion_tracking/calculators/BUILD
@@ -82,3 +82,9 @@ cc_library(
Expand All @@ -48,7 +48,7 @@ index b8242cf..023ef4f 100644
+ visibility = ["//visibility:public"],
+)
diff --git a/mediapipe/graphs/object_detection_3d/calculators/BUILD b/mediapipe/graphs/object_detection_3d/calculators/BUILD
index 5550128..fd8f39e 100644
index 8f80312..e33dd19 100644
--- a/mediapipe/graphs/object_detection_3d/calculators/BUILD
+++ b/mediapipe/graphs/object_detection_3d/calculators/BUILD
@@ -111,3 +111,9 @@ cc_library(
Expand All @@ -73,10 +73,10 @@ index 4471a0c..8508be9 100644
+ visibility = ["//visibility:public"],
)
diff --git a/mediapipe/java/com/google/mediapipe/framework/BUILD b/mediapipe/java/com/google/mediapipe/framework/BUILD
index dd5ae2e..1a26cc2 100644
index ed1a42c..1f31735 100644
--- a/mediapipe/java/com/google/mediapipe/framework/BUILD
+++ b/mediapipe/java/com/google/mediapipe/framework/BUILD
@@ -140,5 +140,5 @@ filegroup(
@@ -141,5 +141,5 @@ filegroup(
["*.java"],
exclude = ["TypeNameRegistryFull.java"],
),
Expand All @@ -94,3 +94,17 @@ index b1c8924..cd10475 100644
- visibility = ["//mediapipe:__subpackages__"],
+ visibility = ["//visibility:public"],
)
diff --git a/mediapipe/modules/face_geometry/protos/BUILD b/mediapipe/modules/face_geometry/protos/BUILD
index 48b7b66..2d53a28 100644
--- a/mediapipe/modules/face_geometry/protos/BUILD
+++ b/mediapipe/modules/face_geometry/protos/BUILD
@@ -44,3 +44,9 @@ mediapipe_proto_library(
name = "mesh_3d_proto",
srcs = ["mesh_3d.proto"],
)
+
+filegroup(
+ name = "protos_src",
+ srcs = glob(["*.proto"]),
+ visibility = ["//visibility:public"],
+)

0 comments on commit 473c3a0

Please sign in to comment.