ScreenLocate.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using ZIM;
  4. using ZIM.Unity;
  5. /// <summary>
  6. /// JC-补充接口
  7. /// </summary>
  8. public partial class ScreenLocate : MonoBehaviour
  9. {
  10. public bool IsScreenLoateOK()
  11. {
  12. return screenIdentification != null &&
  13. screenIdentification.Screen != null &&
  14. screenIdentification.Screen.Active;
  15. }
  16. public bool IsScreenLocateManualDoing()
  17. {
  18. return mode == Mode.ScreenLocateManual;
  19. }
  20. public Texture2D EnterScreenLocateManual()
  21. {
  22. CreateUVCTexture2DIfNeeded();
  23. Texture2D texture = mUVCTexture2D.zimAutoLight(0);
  24. mode = Mode.ScreenLocateManual;
  25. return texture;
  26. }
  27. /// <summary>
  28. /// 屏幕定位时候的实际点转换成算法里面的点
  29. /// 左下、右下、右上、左上 => 左下,右下,左上,右上 (算法)
  30. /// </summary>
  31. /// <param name="points"></param>
  32. public void QuitScreenLocateManual(List<Vector2> points)
  33. {
  34. if (points != null && points.Count == 4)
  35. {
  36. var size = getUVCCameraInfoSize;
  37. screenIdentification?.SetScreenQuad(
  38. new QuadrilateralInCamera(
  39. new o0.Geometry2D.Float.Vector(points[0].x * size.x, points[0].y * size.y),
  40. new o0.Geometry2D.Float.Vector(points[1].x * size.x, points[1].y * size.y),
  41. new o0.Geometry2D.Float.Vector(points[3].x * size.x, points[3].y * size.y),
  42. new o0.Geometry2D.Float.Vector(points[2].x * size.x, points[2].y * size.y),
  43. size.o0Vector()
  44. )
  45. );
  46. }
  47. ToMode(Mode.InfraredLocate);
  48. }
  49. /// <summary>
  50. /// 传入算法对应的点来设置算法屏幕四边形
  51. /// </summary>
  52. /// <param name="points"></param>
  53. public void QuadUnityVectorListToScreenQuad(List<Vector2> points)
  54. {
  55. if (points != null && points.Count == 4)
  56. {
  57. var size = getUVCCameraInfoSize;
  58. screenIdentification?.SetScreenQuad(
  59. new QuadrilateralInCamera(
  60. new o0.Geometry2D.Float.Vector(points[0].x * size.x, points[0].y * size.y),
  61. new o0.Geometry2D.Float.Vector(points[1].x * size.x, points[1].y * size.y),
  62. new o0.Geometry2D.Float.Vector(points[2].x * size.x, points[2].y * size.y),
  63. new o0.Geometry2D.Float.Vector(points[3].x * size.x, points[3].y * size.y),
  64. size.o0Vector()
  65. )
  66. );
  67. }
  68. ToMode(Mode.InfraredLocate);
  69. }
  70. /// <summary>
  71. /// 自动校准
  72. /// </summary>
  73. public void EnterScreenLocateManualAuto()
  74. {
  75. BtnScreenLocate();
  76. }
  77. /// <summary>
  78. /// 设置Capture值,测试用
  79. /// </summary>
  80. /// <param name="value"></param>
  81. public void SetCapture(int value)
  82. {
  83. Capture = value;
  84. }
  85. /// <summary>
  86. /// 设置Delay值,测试用
  87. /// </summary>
  88. /// <param name="value"></param>
  89. public void SetDelay(int value)
  90. {
  91. Delay = value;
  92. }
  93. /// <summary>
  94. /// 校准点位置同步到[调试面板]
  95. /// </summary>
  96. public void SyncInfraredDemo()
  97. {
  98. if (quadUnityVectorList.Count == 0) return;
  99. // Vector2 texSize = getUVCCameraInfoSize;
  100. Debug.Log("[ScreenLocate] SyncInfraredDemo : " + PrintVector2List(quadUnityVectorList));
  101. //同步到infaredDemo
  102. FindObjectOfType<InfraredDemo>()?.SetLocatePointsToCameraRender(
  103. quadUnityVectorList,
  104. 1,
  105. 1);
  106. }
  107. /// <summary>
  108. /// 校准点位置同步到[手动校准页面]
  109. /// </summary>
  110. public void SyncInfraredScreenPositioningView()
  111. {
  112. if (quadUnityVectorList.Count == 0) return;
  113. //同步位置
  114. FindObjectOfType<InfraredScreenPositioningView>()?.SyncScreenPosition();
  115. }
  116. }