common_data.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /// <summary>
  2. /// ZWN-XHJ
  3. /// 20211012
  4. /// </summary>
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. public class common_data : MonoBehaviour
  9. {
  10. public Dictionary<int, Vector3> zwn_single_vec = new Dictionary<int, Vector3>();//关于点数据的存储
  11. List<int> pointIndex = new List<int> { 0, 5, 6, 11, 12, 13, 14, 15, 16 };
  12. Vector3 head, right_hand, left_hand, right_shoulder, left_shoulder,
  13. right_hip, left_hip, right_knee, left_knee, right_ankle, left_ankle, right_ankle_last, left_ankle_last,
  14. chest, right_Elbow, left_Elbow;
  15. [HideInInspector]
  16. public List<int> detail_lists = new List<int> { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  17. bool pose_correct = false;
  18. int lose_num = 0, half_lose_num = 0, half_num_is_pose = 0, num_is_pose = 0;
  19. bool half_pose_correct = false;
  20. public static common_data single;
  21. void Awake()
  22. {
  23. single = this;
  24. for (int i = 0; i < 17; i++)
  25. {
  26. if (zwn_single_vec.ContainsKey(i))
  27. {
  28. zwn_single_vec[i] = new Vector3(-1, -1, 0);
  29. }
  30. else
  31. {
  32. zwn_single_vec.Add(i, new Vector3(-1, -1, 0));
  33. }
  34. }
  35. }
  36. // Update is called once per frame
  37. void Update()
  38. {
  39. //关于点数据的存储和更新
  40. #region
  41. //if (Helper.zwn_pose_true)
  42. //{
  43. // for (int i = 0; i < 17; i++)
  44. // {
  45. // if (zwn_single_vec.ContainsKey(i))
  46. // {
  47. // if (zwn_common_data.single.zwn_pose_cur.point.probs[i] > 0.35f)
  48. // {
  49. // zwn_single_vec[i] =
  50. // new Vector3(
  51. // zwn_common_data.single.zwn_pose_cur.point.landmarks[i].x,
  52. // Helper.Height
  53. // - zwn_common_data.single.zwn_pose_cur.point.landmarks[i].y, 0);
  54. // }
  55. // else
  56. // {
  57. // zwn_single_vec[i] = new Vector3(-1, -1, 0);
  58. // }
  59. // }
  60. // else
  61. // {
  62. // if (zwn_common_data.single.zwn_pose_cur.point.probs[i] > 0.35f)
  63. // {
  64. // zwn_single_vec.Add(i, new Vector3(
  65. // zwn_common_data.single.zwn_original_pose[i].x,
  66. // Helper.Height
  67. // - zwn_common_data.single.zwn_original_pose[i].y, 0));
  68. // }
  69. // else
  70. // {
  71. // zwn_single_vec.Add(i, new Vector3(-1, -1, 0));
  72. // }
  73. // }
  74. // }
  75. //}
  76. #endregion
  77. lose_num = 0;
  78. for (int i = 0; i < pointIndex.Count; i++)
  79. {
  80. if (zwn_single_vec[pointIndex[i]].x == -1 || zwn_single_vec[pointIndex[i]].y == -1)
  81. {
  82. lose_num += 1;
  83. }
  84. else
  85. {
  86. lose_num += 0;
  87. }
  88. }
  89. if (lose_num > 7)
  90. {
  91. num_is_pose += 1;
  92. if (num_is_pose > 30)
  93. {
  94. num_is_pose = 0;
  95. pose_correct = false;
  96. //"最新错误记录:" + "未检测到人体";
  97. detail_lists[2] = 0;
  98. }
  99. }
  100. else
  101. {
  102. pose_correct = true;
  103. //"\n有人";
  104. num_is_pose = 0;
  105. detail_lists[2] = 1;
  106. }
  107. half_lose_num = 0;
  108. for (int i = 0; i < pointIndex.Count - 4; i++)
  109. {
  110. if (zwn_single_vec[pointIndex[i]].x == -1 || zwn_single_vec[pointIndex[i]].y == -1)
  111. {
  112. half_lose_num += 1;
  113. }
  114. else
  115. {
  116. half_lose_num += 0;
  117. }
  118. }
  119. if (half_lose_num > 7 - 4)
  120. {
  121. half_num_is_pose += 1;
  122. if (half_num_is_pose > 30)
  123. {
  124. half_num_is_pose = 0;
  125. half_pose_correct = false;
  126. //"最新错误记录:" + "未检测到人体";
  127. detail_lists[3] = 0;
  128. }
  129. }
  130. else
  131. {
  132. half_pose_correct = true;
  133. //"\n有人";
  134. half_num_is_pose = 0;
  135. detail_lists[3] = 1;
  136. }
  137. }
  138. }