Merge branch 'New_Model' into 'development'
Added model from A - Z See merge request wesign/unity-application!54
This commit was merged in pull request #54.
This commit is contained in:
@@ -53,6 +53,107 @@ public class KeypointManager
|
||||
return (normalized_x, normalized_y);
|
||||
}
|
||||
|
||||
private (List<float>, List<float>) NormalizeHandBohaecek(List<float> hand_x, List<float> hand_y)
|
||||
{
|
||||
|
||||
float min_x = hand_x.Min();
|
||||
float min_y = hand_y.Min();
|
||||
|
||||
float max_x = hand_x.Max();
|
||||
float max_y = hand_y.Max();
|
||||
|
||||
float width = max_x - min_x;
|
||||
float height = max_y - min_y;
|
||||
|
||||
float delta_x = 0;
|
||||
float delta_y = 0;
|
||||
|
||||
if (width == 0 || height == 0)
|
||||
{
|
||||
return (hand_x, hand_y);
|
||||
}
|
||||
|
||||
|
||||
if (width > height){
|
||||
delta_x = ((float)0.1)*width;
|
||||
delta_y = delta_x + ((width - height)/2);
|
||||
}else{
|
||||
delta_y = ((float)0.1)*height;
|
||||
delta_x = delta_y + ((height - width)/2);
|
||||
}
|
||||
|
||||
float starting_x = min_x - delta_x;
|
||||
float starting_y = min_y - delta_y;
|
||||
|
||||
float ending_x = max_x + delta_x;
|
||||
float ending_y = max_y + delta_y;
|
||||
|
||||
float bbox_center_x = (starting_x + ending_x) / 2;
|
||||
float bbox_center_y = (starting_y + ending_y) / 2;
|
||||
|
||||
float bbox_width = ending_x - starting_x;
|
||||
float bbox_height = ending_y - starting_y;
|
||||
|
||||
List<float> normalized_x = new List<float>();
|
||||
List<float> normalized_y = new List<float>();
|
||||
|
||||
for (int i = 0; i < hand_x.Count; i++)
|
||||
{
|
||||
normalized_x.Add((hand_x[i] - bbox_center_x) / bbox_width);
|
||||
normalized_y.Add((hand_y[i] - bbox_center_y) / bbox_height);
|
||||
}
|
||||
|
||||
return (normalized_x, normalized_y);
|
||||
}
|
||||
|
||||
public (List<float>, List<float>) PoseNormalization(List<float> pose_x, List<float> pose_y)
|
||||
{
|
||||
|
||||
float bbox_size = ((float)4.0);
|
||||
|
||||
float shoulder_left_x = pose_x[6];
|
||||
float shoulder_left_y = pose_y[6];
|
||||
|
||||
float shoulder_right_x = pose_x[7];
|
||||
float shoulder_right_y = pose_y[7];
|
||||
|
||||
float shoulder_distance = Mathf.Sqrt(Mathf.Pow(shoulder_left_x - shoulder_right_x, 2) + Mathf.Pow(shoulder_left_y - shoulder_right_y, 2));
|
||||
float shoulder_center_x = (shoulder_left_x + shoulder_right_x) / 2;
|
||||
float shoulder_center_y = (shoulder_left_y + shoulder_right_y) / 2;
|
||||
|
||||
float eye_left_x = pose_x[1];
|
||||
float eye_left_y = pose_y[1];
|
||||
|
||||
float starting_x = shoulder_center_x - (bbox_size/2) * shoulder_distance;
|
||||
float starting_y = eye_left_y - shoulder_distance/2;
|
||||
|
||||
float ending_x = shoulder_center_x + (bbox_size/2) * shoulder_distance;
|
||||
float ending_y = starting_y + (bbox_size - ((float)0.5)) * shoulder_distance;
|
||||
|
||||
float bbox_center_x = (starting_x + ending_x) / 2;
|
||||
float bbox_center_y = (starting_y + ending_y) / 2;
|
||||
|
||||
float bbox_width = ending_x - starting_x;
|
||||
float bbox_height = ending_y - starting_y;
|
||||
|
||||
if (bbox_width == 0 || bbox_height == 0)
|
||||
{
|
||||
return (pose_x, pose_y);
|
||||
}
|
||||
|
||||
List<float> normalized_x = new List<float>();
|
||||
List<float> normalized_y = new List<float>();
|
||||
|
||||
for (int i = 0; i < pose_x.Count; i++)
|
||||
{
|
||||
normalized_x.Add((pose_x[i] - bbox_center_x) / bbox_width);
|
||||
normalized_y.Add((pose_y[i] - bbox_center_y) / bbox_height);
|
||||
}
|
||||
|
||||
return (normalized_x, normalized_y);
|
||||
}
|
||||
|
||||
|
||||
public void AddLandmarks(NormalizedLandmarkList poseLandmarks, NormalizedLandmarkList leftHandLandmarks, NormalizedLandmarkList rightHandLandmarks)
|
||||
{
|
||||
List<float> pose_x = new List<float>();
|
||||
@@ -105,11 +206,9 @@ public class KeypointManager
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add normalization
|
||||
//Debug.Log($"pose_landMarks = [{modelInfo.pose_landmarks.Aggregate(" ", (t, f) => $"{t} {f}")}]");
|
||||
//Debug.Log($"hand_landmarks = [{modelInfo.hand_landmarks.Aggregate(" ", (t, f) => $"{t} {f}")}]");
|
||||
(left_hand_x, left_hand_y) = NormalizeHand(left_hand_x, left_hand_y);
|
||||
(right_hand_x, right_hand_y) = NormalizeHand(right_hand_x, right_hand_y);
|
||||
(pose_x, pose_y) = PoseNormalization(pose_x, pose_y);
|
||||
(left_hand_x, left_hand_y) = NormalizeHandBohaecek(left_hand_x, left_hand_y);
|
||||
(right_hand_x, right_hand_y) = NormalizeHandBohaecek(right_hand_x, right_hand_y);
|
||||
|
||||
|
||||
if (keypointsBuffer.Count >= 10)
|
||||
|
||||
Reference in New Issue
Block a user