Skip to content

Commit

Permalink
Merge pull request #17 from creativeIKEP/develop
Browse files Browse the repository at this point in the history
v1.3.0
  • Loading branch information
creativeIKEP authored Sep 25, 2022
2 parents be6db72 + 80d045a commit 809c62b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 91 deletions.
3 changes: 3 additions & 0 deletions Packages/BlazePoseBarracuda/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### [1.3.0] - 2022-09-25
Improved performance difference by FPS.

### [1.2.0] - 2021-02-15
- Improve the stability of pose estimation.
- Fixed an issue that pose estimation was not performed correctly when the color space was Liner.
Expand Down
10 changes: 5 additions & 5 deletions Packages/BlazePoseBarracuda/ComputeShader/Process.compute
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void LetterBoxImage(uint2 id : SV_DispatchThreadID)

// Kernel 1
float _deltaTime;
uint _upperBodyOnly;
StructuredBuffer<PoseDetection> _poseDetections;
ByteAddressBuffer _poseDetectionCount;
RWStructuredBuffer<PoseRegion> _poseRegions;
Expand All @@ -72,8 +71,8 @@ void PoseRegionUpdate(uint id : SV_DispatchThreadID)
float2 shoulder = pd.keyPoints[2];

// Rotation center point
float2 center = _upperBodyOnly ? shoulder : hip;
float2 roi = _upperBodyOnly ? pd.keyPoints[3] : pd.keyPoints[1];
float2 center = hip;
float2 roi = pd.keyPoints[1];

// Image crop size
float sizeX = abs(roi.x - center.x);
Expand Down Expand Up @@ -153,7 +152,6 @@ void CropImage(uint2 id : SV_DispatchThreadID)
uint _isWorldProcess;
uint _keypointCount;
float _postDeltatime;
float _velocity_scale;
uint _rvfWindowCount;

StructuredBuffer<float4> _postInput;
Expand All @@ -167,6 +165,8 @@ RWStructuredBuffer<float4> _postOutput;
[numthreads(33 + 1, 1, 1)]
void PostProcess(uint id : SV_DispatchThreadID)
{
const float VELOCITY_SCALE = 0.1f;

if(id > _keypointCount) return;

if(id == _keypointCount){
Expand Down Expand Up @@ -228,7 +228,7 @@ void PostProcess(uint id : SV_DispatchThreadID)
}

float3 velocity = distance_sum / duration_sum;
float3 alpha = 1.0 - 1.0 / (1.0 + _velocity_scale * abs(velocity));
float3 alpha = 1.0 - 1.0 / (1.0 + VELOCITY_SCALE * abs(velocity));
x = lerp(p_x, x, alpha);

// window enqueue & dequeue for next frame
Expand Down
115 changes: 47 additions & 68 deletions Packages/BlazePoseBarracuda/Documentation~/BlazePoseBarracuda.md
Original file line number Diff line number Diff line change
@@ -1,90 +1,69 @@
# BlazePoseBarracuda Usage Documentation
### Dependencies
## Dependencies
BlazePoseBarracuda uses the following sub packages:
- [PoseDetectionBarracuda](https://github.com/creativeIKEP/PoseDetectionBarracuda)
- [PoseLandmarkBarracuda](https://github.com/creativeIKEP/PoseLandmarkBarracuda)

### Install
## Install
BlazePoseBarracuda can be installed from npm or GitHub URL.

### Install from npm (Recommend)
BlazePoseBarracuda can be installed by adding following sections to the manifest file (`Packages/manifest.json`).

To the `scopedRegistries` section:
```
{
"name": "creativeikep",
"url": "https://registry.npmjs.com",
"scopes": [ "jp.ikep" ]
}
```
To the `dependencies` section:
```
"jp.ikep.mediapipe.blazepose": "1.3.0"
```
Finally, the manifest file looks like below:
```
{
"scopedRegistries": [
{
"name": "creativeikep",
"url": "https://registry.npmjs.com",
"scopes": [ "jp.ikep" ]
}
],
"dependencies": {
"jp.ikep.mediapipe.blazepose": "1.3.0",
...
}
}
```

### Install from GitHub URL
BlazePoseBarracuda can be installed by adding below URLs from the Unity Package Manager's window
```
https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDetectionBarracuda#v1.0.0
https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDetectionBarracuda#v1.0.1
```
```
https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.0.1
https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.1.1
```
```
https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.0.0
https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.3.0
```
or, appending lines to your manifest file(`Packages/manifest.json`) `dependencies` block.
Example is below.
```
{
"dependencies": {
"jp.ikep.mediapipe.posedetection": "https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDetectionBarracuda#v1.0.0",
"jp.ikep.mediapipe.poselandmark": "https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.0.1",
"jp.ikep.mediapipe.blazepose": "https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.0.0",
"jp.ikep.mediapipe.posedetection": "https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDetectionBarracuda#v1.0.1",
"jp.ikep.mediapipe.poselandmark": "https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.1.1",
"jp.ikep.mediapipe.blazepose": "https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.3.0",
...
}
}
```

### Usage Demo
Below code is the demo that estimate human pose from a image and get pose landmark.
Check ["/Assets/Script/PoseVisuallizer.cs"](https://github.com/creativeIKEP/BlazePoseBarracuda/blob/main/Assets/Script/PoseVisuallizer.cs) and ["/Assets/Scenes/SampleScene.unity"](https://github.com/creativeIKEP/BlazePoseBarracuda/blob/main/Assets/Scenes/SampleScene.unity) for BlazePoseBarracuda usage demo details.
```cs
using UnityEngine;
using Mediapipe.BlazePose;

public class <YourClassName>: MonoBehaviour
{
// Set "Packages/BlazePoseBarracuda/ResourceSet/BlazePose.asset" on the Unity Editor.
[SerializeField] BlazePoseResource blazePoseResource;
[SerializeField] bool isUpperBodyOnly;

BlazePoseDetecter detecter;

void Start(){
detecter = new BlazePoseDetecter(blazePoseResource, isUpperBodyOnly);
}

void Update(){
Texture input = ...; // Your input image texture
// Predict pose by neural network model.
// Switchable anytime between upper body and full body with 2nd argment.
detecter.ProcessImage(input, isUpperBodyOnly);

/*
`detecter.outputBuffer` is pose landmark result and ComputeBuffer of float4 array type.
0~(24 or 32) index datas are pose landmark.
Check below Mediapipe document about relation between index and landmark position.
https://google.github.io/mediapipe/solutions/pose#pose_landmarks
Each data factors are
x: x cordinate value of pose landmark ([0, 1]).
y: y cordinate value of pose landmark ([0, 1]).
z: Landmark depth with the depth at the midpoint of hips being the origin.
The smaller the value the closer the landmark is to the camera. ([0, 1]).
This value is full body mode only.
**The use of this value is not recommended beacuse in development.**
w: The score of whether the landmark position is visible ([0, 1]).
(25 or 33) index data is the score whether human pose is visible ([0, 1]).
This data is (score, 0, 0, 0).
*/
ComputeBuffer result = detecter.outputBuffer;

// `detecter.vertexCount` is count of pose landmark vertices.
// `detecter.vertexCount` returns 25 or 33 by upper or full body mode.
int count = detecter.vertexCount;

// Your custom processing from here, i.e. rendering.
// For example, below is CPU log debug.
var data = new Vector4[count];
result.GetData(data);
Debug.Log("---");
foreach(var d in data){
Debug.Log(d);
}
}
}
```
## Usage Demo
This repository has the demo for inferencing pose and visualizing landmarks.
Check ["/Assets/Script/PoseVisuallizer.cs"](https://github.com/creativeIKEP/BlazePoseBarracuda/blob/main/Assets/Script/PoseVisuallizer.cs) and ["/Assets/Scenes/2DSampleScene.unity"](https://github.com/creativeIKEP/BlazePoseBarracuda/blob/main/Assets/Scenes/2DSampleScene.unity) for BlazePoseBarracuda usage demo details in the 2D pose estimation.
Check ["/Assets/Script/PoseVisuallizer3D.cs"](https://github.com/creativeIKEP/BlazePoseBarracuda/blob/main/Assets/Script/PoseVisuallizer3D.cs) and ["/Assets/Scenes/3DSampleScene.unity"](https://github.com/creativeIKEP/BlazePoseBarracuda/blob/main/Assets/Scenes/3DSampleScene.unity) for BlazePoseBarracuda usage demo details in the 3D pose estimation.
8 changes: 4 additions & 4 deletions Packages/BlazePoseBarracuda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ To the `scopedRegistries` section:
```
To the `dependencies` section:
```
"jp.ikep.mediapipe.blazepose": "1.2.0"
"jp.ikep.mediapipe.blazepose": "1.3.0"
```
Finally, the manifest file looks like below:
```
Expand All @@ -42,7 +42,7 @@ Finally, the manifest file looks like below:
}
],
"dependencies": {
"jp.ikep.mediapipe.blazepose": "1.2.0",
"jp.ikep.mediapipe.blazepose": "1.3.0",
...
}
}
Expand All @@ -57,7 +57,7 @@ https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDet
https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.1.1
```
```
https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.2.0
https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.3.0
```
or, appending lines to your manifest file(`Packages/manifest.json`) `dependencies` block.
Example is below.
Expand All @@ -66,7 +66,7 @@ Example is below.
"dependencies": {
"jp.ikep.mediapipe.posedetection": "https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDetectionBarracuda#v1.0.1",
"jp.ikep.mediapipe.poselandmark": "https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.1.1",
"jp.ikep.mediapipe.blazepose": "https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.2.0",
"jp.ikep.mediapipe.blazepose": "https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.3.0",
...
}
}
Expand Down
13 changes: 4 additions & 9 deletions Packages/BlazePoseBarracuda/Script/BlazePoseDetecter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void ProcessImage(
Mathf.Max((float)inputTexture.height / inputTexture.width, 1),
Mathf.Max(1, (float)inputTexture.width / inputTexture.height)
);
float deltaTime = 1.0f / (4500.0f * Time.unscaledDeltaTime);

// Image scaling and padding
// Output image is letter-box image.
Expand All @@ -117,8 +118,7 @@ public void ProcessImage(
detecter.ProcessImage(letterboxTextureBuffer, poseThreshold, iouThreshold);

// Update Pose Region from detected results.
cs.SetFloat("_deltaTime", Time.deltaTime);
cs.SetInt("_upperBodyOnly", 0);
cs.SetFloat("_deltaTime", deltaTime);
cs.SetBuffer(1, "_poseDetections", detecter.outputBuffer);
cs.SetBuffer(1, "_poseDetectionCount", detecter.countBuffer);
cs.SetBuffer(1, "_poseRegions", poseRegionBuffer);
Expand All @@ -133,14 +133,10 @@ public void ProcessImage(
// Predict pose landmark.
landmarker.ProcessImage(cropedTextureBuffer, (PoseLandmarkModel)blazePoseModel);

float fps = 1.0f / Time.unscaledDeltaTime;
float velocity_scale = 1.0f / fps;

// Map to cordinates of `inputTexture` from pose landmarks on croped letter-box image.
cs.SetInt("_isWorldProcess", 0);
cs.SetInt("_keypointCount", landmarker.vertexCount);
cs.SetFloat("_postDeltatime", Time.deltaTime);
cs.SetFloat("_velocity_scale", velocity_scale);
cs.SetFloat("_postDeltatime", deltaTime);
cs.SetInt("_rvfWindowCount", rvfWindowCount);
cs.SetBuffer(3, "_postInput", landmarker.outputBuffer);
cs.SetBuffer(3, "_postRegion", poseRegionBuffer);
Expand All @@ -152,8 +148,7 @@ public void ProcessImage(
// Map to cordinates of `inputTexture` from pose landmarks on croped letter-box image for 3D world landmarks.
cs.SetInt("_isWorldProcess", 1);
cs.SetInt("_keypointCount", landmarker.vertexCount);
cs.SetFloat("_postDeltatime", Time.deltaTime);
cs.SetFloat("_velocity_scale", velocity_scale);
cs.SetFloat("_postDeltatime", deltaTime);
cs.SetInt("_rvfWindowCount", rvfWindowCount);
cs.SetBuffer(3, "_postInput", landmarker.worldLandmarkBuffer);
cs.SetBuffer(3, "_postRegion", poseRegionBuffer);
Expand Down
2 changes: 1 addition & 1 deletion Packages/BlazePoseBarracuda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "jp.ikep.mediapipe.blazepose",
"displayName": "BlazePoseBarracuda",
"description": "BlazePose (Mediapipe Pose) for Unity Barracuda.",
"version": "1.2.0",
"version": "1.3.0",
"unity": "2020.3",
"unityRelease": "6f1",
"keywords": [
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ To the `scopedRegistries` section:
```
To the `dependencies` section:
```
"jp.ikep.mediapipe.blazepose": "1.2.0"
"jp.ikep.mediapipe.blazepose": "1.3.0"
```
Finally, the manifest file looks like below:
```
Expand All @@ -42,7 +42,7 @@ Finally, the manifest file looks like below:
}
],
"dependencies": {
"jp.ikep.mediapipe.blazepose": "1.2.0",
"jp.ikep.mediapipe.blazepose": "1.3.0",
...
}
}
Expand All @@ -57,7 +57,7 @@ https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDet
https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.1.1
```
```
https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.2.0
https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.3.0
```
or, appending lines to your manifest file(`Packages/manifest.json`) `dependencies` block.
Example is below.
Expand All @@ -66,7 +66,7 @@ Example is below.
"dependencies": {
"jp.ikep.mediapipe.posedetection": "https://github.com/creativeIKEP/PoseDetectionBarracuda.git?path=Packages/PoseDetectionBarracuda#v1.0.1",
"jp.ikep.mediapipe.poselandmark": "https://github.com/creativeIKEP/PoseLandmarkBarracuda.git?path=Packages/PoseLandmarkBarracuda#v1.1.1",
"jp.ikep.mediapipe.blazepose": "https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.2.0",
"jp.ikep.mediapipe.blazepose": "https://github.com/creativeIKEP/BlazePoseBarracuda.git?path=Packages/BlazePoseBarracuda#v1.3.0",
...
}
}
Expand Down

0 comments on commit 809c62b

Please sign in to comment.