Skip to content

Commit

Permalink
feat(example): enable to get pose world landmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Jul 11, 2021
1 parent 58084e8 commit abbade0
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ input_stream: "input_video"
input_side_packet: "enable_iris_detection"

output_stream: "pose_landmarks"
output_stream: "pose_world_landmarks"
output_stream: "pose_roi"
output_stream: "pose_detection"
output_stream: "face_landmarks"
Expand Down Expand Up @@ -88,6 +89,7 @@ node {
calculator: "HolisticLandmarkGpu"
input_stream: "IMAGE:transformed_input_video"
output_stream: "POSE_LANDMARKS:pose_landmarks"
output_stream: "WORLD_LANDMARKS:pose_world_landmarks"
output_stream: "POSE_ROI:pose_roi"
output_stream: "POSE_DETECTION:pose_detection"
output_stream: "FACE_LANDMARKS:face_landmarks_orig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ input_stream: "input_video"
input_side_packet: "enable_iris_detection"

output_stream: "pose_landmarks"
output_stream: "pose_world_landmarks"
output_stream: "pose_roi"
output_stream: "pose_detection"
output_stream: "face_landmarks"
Expand Down Expand Up @@ -88,6 +89,7 @@ node {
calculator: "HolisticLandmarkCpu"
input_stream: "IMAGE:transformed_input_video"
output_stream: "POSE_LANDMARKS:pose_landmarks"
output_stream: "WORLD_LANDMARKS:pose_world_landmarks"
output_stream: "POSE_ROI:pose_roi"
output_stream: "POSE_DETECTION:pose_detection"
output_stream: "FACE_LANDMARKS:face_landmarks_orig"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ input_stream: "input_video"
input_side_packet: "enable_iris_detection"

output_stream: "pose_landmarks"
output_stream: "pose_world_landmarks"
output_stream: "pose_roi"
output_stream: "pose_detection"
output_stream: "face_landmarks"
Expand Down Expand Up @@ -95,6 +96,7 @@ node {
calculator: "HolisticLandmarkGpu"
input_stream: "IMAGE:transformed_input_video"
output_stream: "POSE_LANDMARKS:pose_landmarks"
output_stream: "WORLD_LANDMARKS:pose_world_landmarks"
output_stream: "POSE_ROI:pose_roi"
output_stream: "POSE_DETECTION:pose_detection"
output_stream: "FACE_LANDMARKS:face_landmarks_orig"
Expand Down
11 changes: 11 additions & 0 deletions Assets/Mediapipe/Samples/Graphs/Holistic/Scripts/HolisticGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ enum ModelComplexity {
private OutputStreamPoller<NormalizedLandmarkList> poseLandmarksStreamPoller;
private NormalizedLandmarkListPacket poseLandmarksPacket;

private const string poseWorldLandmarksStream = "pose_world_landmarks";
private OutputStreamPoller<LandmarkList> poseWorldLandmarksStreamPoller;
private LandmarkListPacket poseWorldLandmarksPacket;

private const string poseRoiStream = "pose_roi";
private OutputStreamPoller<NormalizedRect> poseRoiStreamPoller;
private NormalizedRectPacket poseRoiPacket;
Expand Down Expand Up @@ -66,6 +70,9 @@ enum ModelComplexity {
poseLandmarksStreamPoller = graph.AddOutputStreamPoller<NormalizedLandmarkList>(poseLandmarksStream).Value();
poseLandmarksPacket = new NormalizedLandmarkListPacket();

poseWorldLandmarksStreamPoller = graph.AddOutputStreamPoller<LandmarkList>(poseWorldLandmarksStream).Value();
poseWorldLandmarksPacket = new LandmarkListPacket();

poseRoiStreamPoller = graph.AddOutputStreamPoller<NormalizedRect>(poseRoiStream).Value();
poseRoiPacket = new NormalizedRectPacket();

Expand Down Expand Up @@ -136,6 +143,10 @@ enum ModelComplexity {
return FetchNext(poseLandmarksStreamPoller, poseLandmarksPacket, poseLandmarksStream);
}

private LandmarkList FetchNextPoseWorldLandmarks() {
return FetchNext(poseWorldLandmarksStreamPoller, poseWorldLandmarksPacket, poseWorldLandmarksStream);
}

private NormalizedRect FetchNextPoseRoi() {
return FetchNext(poseRoiStreamPoller, poseRoiPacket, poseRoiStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
input_stream: "input_video"

output_stream: "pose_landmarks"
output_stream: "pose_world_landmarks"
output_stream: "pose_detection"
output_stream: "pose_landmarks_presence"
output_stream: "pose_detection_presence"
Expand Down Expand Up @@ -65,6 +66,7 @@ node {
calculator: "PoseLandmarkGpu"
input_stream: "IMAGE:transformed_input_video"
output_stream: "LANDMARKS:pose_landmarks"
output_stream: "WORLD_LANDMARKS:pose_world_landmarks"
output_stream: "DETECTION:pose_detection"
output_stream: "ROI_FROM_LANDMARKS:roi_from_landmarks"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
input_stream: "input_video"

output_stream: "pose_landmarks"
output_stream: "pose_world_landmarks"
output_stream: "pose_detection"
output_stream: "pose_landmarks_presence"
output_stream: "pose_detection_presence"
Expand Down Expand Up @@ -65,6 +66,7 @@ node {
calculator: "PoseLandmarkCpu"
input_stream: "IMAGE:transformed_input_video"
output_stream: "LANDMARKS:pose_landmarks"
output_stream: "WORLD_LANDMARKS:pose_world_landmarks"
output_stream: "DETECTION:pose_detection"
output_stream: "ROI_FROM_LANDMARKS:roi_from_landmarks"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
input_stream: "input_video"

output_stream: "pose_landmarks"
output_stream: "pose_world_landmarks"
output_stream: "pose_detection"
output_stream: "pose_landmarks_presence"
output_stream: "pose_detection_presence"
Expand Down Expand Up @@ -72,6 +73,7 @@ node {
calculator: "PoseLandmarkGpu"
input_stream: "IMAGE:transformed_input_video"
output_stream: "LANDMARKS:pose_landmarks"
output_stream: "WORLD_LANDMARKS:pose_world_landmarks"
output_stream: "DETECTION:pose_detection"
output_stream: "ROI_FROM_LANDMARKS:roi_from_landmarks"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ enum ModelComplexity {
private OutputStreamPoller<NormalizedLandmarkList> poseLandmarksStreamPoller;
private NormalizedLandmarkListPacket poseLandmarksPacket;

private const string poseWorldLandmarksStream = "pose_world_landmarks";
private OutputStreamPoller<LandmarkList> poseWorldLandmarksStreamPoller;
private LandmarkListPacket poseWorldLandmarksPacket;

private const string poseDetectionStream = "pose_detection";
private OutputStreamPoller<Detection> poseDetectionStreamPoller;
private DetectionPacket poseDetectionPacket;
Expand All @@ -33,6 +37,9 @@ enum ModelComplexity {
poseLandmarksStreamPoller = graph.AddOutputStreamPoller<NormalizedLandmarkList>(poseLandmarksStream).Value();
poseLandmarksPacket = new NormalizedLandmarkListPacket();

poseWorldLandmarksStreamPoller = graph.AddOutputStreamPoller<LandmarkList>(poseWorldLandmarksStream).Value();
poseWorldLandmarksPacket = new LandmarkListPacket();

poseDetectionStreamPoller = graph.AddOutputStreamPoller<Detection>(poseDetectionStream).Value();
poseDetectionPacket = new DetectionPacket();

Expand Down Expand Up @@ -76,6 +83,10 @@ enum ModelComplexity {
return FetchNext(poseLandmarksStreamPoller, poseLandmarksPacket, poseLandmarksStream);
}

private LandmarkList FetchNextPoseWorldLandmarks() {
return FetchNext(poseWorldLandmarksStreamPoller, poseWorldLandmarksPacket, poseWorldLandmarksStream);
}

private Detection FetchNextPoseDetection() {
return FetchNext(poseDetectionStreamPoller, poseDetectionPacket, poseDetectionStream);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

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

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

var landmarkList = Protobuf.DeserializeProto<LandmarkList>(serializedProtoPtr, LandmarkList.Parser);
UnsafeNativeMethods.mp_api_SerializedProto__delete(serializedProtoPtr);

return landmarkList;
}

public override StatusOr<LandmarkList> 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 LandmarkListVectorPacket : Packet<List<LandmarkList>> {
public LandmarkListVectorPacket() : base() {}
public LandmarkListVectorPacket(IntPtr ptr, bool isOwner = true) : base(ptr, isOwner) {}

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

var landmarkLists = Protobuf.DeserializeProtoVector<LandmarkList>(serializedProtoVectorPtr, LandmarkList.Parser);
UnsafeNativeMethods.mp_api_SerializedProtoVector__delete(serializedProtoVectorPtr);

return landmarkLists;
}

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

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

2 comments on commit abbade0

@TheBricktop
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank You!

@ROBYER1
Copy link
Contributor

@ROBYER1 ROBYER1 commented on abbade0 Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any tips on how to get this working and showing when using the Holistic graph example?

Please sign in to comment.