| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- /// <summary>
- /// ZWN
- /// 20220104
- /// </summary>
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- //using zwn;
- /// <summary>
- /// 显示对齐框的框工具类接口
- /// </summary>
- public class FollowBoxManager : MonoBehaviour
- {
- public static FollowBoxManager sigle;
- float[] pose_kpts = new float[4 * 2];//4个点的坐标
- int pose_kpts_count = 4;//数量
- public GameObject show_rect_perfab;//克隆物体
- public Transform show_rect_tra;//克隆物体父级
- [HideInInspector]
- public List<GameObject> show_rect_list;//克隆出来的物体
- //固定框
- public int x; ///< 左上角顶点 X 轴坐标
- public int y; ///< 左上角顶点 Y 轴坐标
- public int width; ///< 矩形的宽度
- public int height; ///< 矩形的高度
- public bool isShowFollowBox = false;
- public static float followRatio = 0f;
- // dataType.zwn_rect_t_fixedframe aligned_Rect = new dataType.zwn_rect_t_fixedframe();
- private bool isAlignmentSuccee;
- public bool GetIsSuccee
- {
- get { return isAlignmentSuccee; }
- set { isAlignmentSuccee = value; }
- }
- void Awake()
- {
- sigle = this;
- }
- // Use this for initialization
- void Start()
- {
- //aligned_Rect.x = x;
- //aligned_Rect.y = y;
- //aligned_Rect.width = width;
- //aligned_Rect.height = height;
- GetCurrFollow();
- }
- // Update is called once per frame
- void Update()
- {
- ShowFollowBox();
- GetRectRatio();
- GetIsinclude();
- }
- /// <summary>
- ///计算关键点的矩形框
- /// </summary>
- void ShowFollowBox()
- {
- if (!ZwnAmlogicHelperData.isSomeone)
- {
- return;
- }
- if (ZwnAmlogicHelperData.ZWN_POSE_KEY_POINTS_DIM_LEN == 29)
- {
- if (Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[5].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[6].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[17].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[18].x) != 1920)
- {
- pose_kpts[0] = zwn_common_data.single.zwn_original_pose_twentynine[5].x;
- pose_kpts[1] = zwn_common_data.single.zwn_original_pose_twentynine[5].y;
- pose_kpts[2] = zwn_common_data.single.zwn_original_pose_twentynine[6].x;
- pose_kpts[3] = zwn_common_data.single.zwn_original_pose_twentynine[6].y;
- pose_kpts[4] = zwn_common_data.single.zwn_original_pose_twentynine[17].x;
- pose_kpts[5] = zwn_common_data.single.zwn_original_pose_twentynine[17].y;
- pose_kpts[6] = zwn_common_data.single.zwn_original_pose_twentynine[18].x;
- pose_kpts[7] = zwn_common_data.single.zwn_original_pose_twentynine[18].y;
- }
- //utilCAPI.zwn_get_bounding_rect(pose_kpts, pose_kpts_count, ref UtilHelper.zwn_rect_t_alignments);
- float x = (zwn_common_data.single.zwn_transform_pose_twentynine[5].x + zwn_common_data.single.zwn_transform_pose_twentynine[6].x) / 2;
- float y = (zwn_common_data.single.zwn_transform_pose_twentynine[5].y + zwn_common_data.single.zwn_transform_pose_twentynine[17].y) / 2;
- float height = Vector3.Distance(zwn_common_data.single.zwn_transform_pose_twentynine[5], zwn_common_data.single.zwn_transform_pose_twentynine[17]);
- float width = Vector3.Distance(zwn_common_data.single.zwn_transform_pose_twentynine[5], zwn_common_data.single.zwn_transform_pose_twentynine[6]);
- Vector2 rect_weightheight = new Vector2(width, height);
- Vector3 rect_xy = new Vector3(x, y, 0);
- if (isShowFollowBox)
- {
- for (int i = 0; i < 1; i++)
- {
- //关于人形框
- if (i >= show_rect_list.Count)
- {
- GameObject go = Instantiate(show_rect_perfab);
- show_rect_list.Add(go);
- go.transform.SetParent(show_rect_tra);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- show_rect_list[i].transform.localPosition = rect_xy;
- show_rect_list[i].GetComponent<RectTransform>().sizeDelta = rect_weightheight;
- }
- }
- }
- else if (ZwnAmlogicHelperData.ZWN_POSE_KEY_POINTS_DIM_LEN == 17)
- {
- if (Mathf.Abs(zwn_common_data.single.zwn_transform_pose[5].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose[6].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose[11].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose[12].x) != 1920)
- {
- pose_kpts[0] = zwn_common_data.single.zwn_original_pose[5].x;
- pose_kpts[1] = zwn_common_data.single.zwn_original_pose[5].y;
- pose_kpts[2] = zwn_common_data.single.zwn_original_pose[6].x;
- pose_kpts[3] = zwn_common_data.single.zwn_original_pose[6].y;
- pose_kpts[4] = zwn_common_data.single.zwn_original_pose[11].x;
- pose_kpts[5] = zwn_common_data.single.zwn_original_pose[11].y;
- pose_kpts[6] = zwn_common_data.single.zwn_original_pose[12].x;
- pose_kpts[7] = zwn_common_data.single.zwn_original_pose[12].y;
- }
- //utilCAPI.zwn_get_bounding_rect(pose_kpts, pose_kpts_count, ref UtilHelper.zwn_rect_t_alignments);
- float x = (zwn_common_data.single.zwn_transform_pose[5].x + zwn_common_data.single.zwn_transform_pose[6].x) / 2;
- float y = (zwn_common_data.single.zwn_transform_pose[5].y + zwn_common_data.single.zwn_transform_pose[11].y) / 2;
- float height = Vector3.Distance(zwn_common_data.single.zwn_transform_pose[5], zwn_common_data.single.zwn_transform_pose[11]);
- float width = Vector3.Distance(zwn_common_data.single.zwn_transform_pose[5], zwn_common_data.single.zwn_transform_pose[6]);
- Vector2 rect_weightheight = new Vector2(width, height);
- Vector3 rect_xy = new Vector3(x, y, 0);
- if (isShowFollowBox)
- {
- for (int i = 0; i < 1; i++)
- {
- //关于人形框
- if (i >= show_rect_list.Count)
- {
- GameObject go = Instantiate(show_rect_perfab);
- show_rect_list.Add(go);
- go.transform.SetParent(show_rect_tra);
- go.transform.localScale = new Vector3(1, 1, 1);
- }
- show_rect_list[i].transform.localPosition = rect_xy;
- show_rect_list[i].GetComponent<RectTransform>().sizeDelta = rect_weightheight;
- }
- }
- }
- }
- /// <summary>
- /// 当计算两个框的IOU分数小于thres阈值时,ratio 返回的是IOU的分数。(0.5-2)
- /// </summary>
- void GetRectRatio()
- {
- //utilCAPI.zwn_get_rect_ratio(UtilHelper.zwn_rect_t_alignments, aligned_Rect, 0.1f, ref followRatio);
- //print("followRatio " + followRatio);
- }
- /// <summary>
- /// 坐标转换
- /// </summary>
- void GetCurrFollow()
- {
- int width = Screen.width;
- int height = Screen.height;
- //aligned_Rect.x = width / 2 + aligned_Rect.x;
- //aligned_Rect.y = height / 2 - aligned_Rect.y;
- }
- /// <summary>
- /// 判断身体框是否在对齐框内
- /// </summary>
- public void GetIsinclude()
- {
- float x1 = -(width / 2);
- float x2 = width / 2;
- float y1 = -(height / 2);
- float y2 = height / 2;
- bool isinclude = false;
- bool isinclude1 = false;
- bool isinclude2 = false;
- bool isinclude3 = false;
- bool isinclude4 = false;
- bool isinclude5 = false;
- bool isinclude6 = false;
- bool isinclude7 = false;
- if (!ZwnAmlogicHelperData.isSomeone)
- {
- return;
- }
- if (ZwnAmlogicHelperData.ZWN_POSE_KEY_POINTS_DIM_LEN == 29)
- {
- if (Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[5].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[6].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[17].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose_twentynine[18].x) != 1920)
- {
- isinclude = zwn_common_data.single.zwn_transform_pose_twentynine[6].x > x1;
- isinclude1 = zwn_common_data.single.zwn_transform_pose_twentynine[6].y < y2;
- isinclude2 = zwn_common_data.single.zwn_transform_pose_twentynine[17].x < x2;
- isinclude3 = zwn_common_data.single.zwn_transform_pose_twentynine[17].y > y1;
- isinclude4 = zwn_common_data.single.zwn_transform_pose_twentynine[5].x < x2;
- isinclude5 = zwn_common_data.single.zwn_transform_pose_twentynine[5].y < y2;
- isinclude6 = zwn_common_data.single.zwn_transform_pose_twentynine[18].x > x1;
- isinclude7 = zwn_common_data.single.zwn_transform_pose_twentynine[18].y > y1;
- }
- if (isinclude && isinclude1 && isinclude2 && isinclude3 && isinclude4 && isinclude5 && isinclude6 && isinclude7)
- {
- isAlignmentSuccee = true;
- }
- else
- {
- isAlignmentSuccee = false;
- }
- }
- else if (ZwnAmlogicHelperData.ZWN_POSE_KEY_POINTS_DIM_LEN == 17)
- {
- if (Mathf.Abs(zwn_common_data.single.zwn_transform_pose[5].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose[6].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose[11].x) != 1920 && Mathf.Abs(zwn_common_data.single.zwn_transform_pose[12].x) != 1920)
- {
- isinclude = zwn_common_data.single.zwn_transform_pose[6].x > x1;
- isinclude1 = zwn_common_data.single.zwn_transform_pose[6].y < y2;
- isinclude2 = zwn_common_data.single.zwn_transform_pose[11].x < x2;
- isinclude3 = zwn_common_data.single.zwn_transform_pose[11].y > y1;
- isinclude4 = zwn_common_data.single.zwn_transform_pose[5].x < x2;
- isinclude5 = zwn_common_data.single.zwn_transform_pose[5].y < y2;
- isinclude6 = zwn_common_data.single.zwn_transform_pose[12].x > x1;
- isinclude7 = zwn_common_data.single.zwn_transform_pose[12].y > y1;
- }
- if (isinclude && isinclude1 && isinclude2 && isinclude3 && isinclude4 && isinclude5 && isinclude6 && isinclude7)
- {
- isAlignmentSuccee = true;
- }
- else
- {
- isAlignmentSuccee = false;
- }
- }
- }
- }
|