ScreenLocate.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. Debug.Log("QuitScreenLocateManual Size:" + size);
  38. screenIdentification?.SetScreenQuad(
  39. new QuadrilateralInCamera(
  40. new o0.Geometry2D.Float.Vector(points[0].x * size.x, points[0].y * size.y),
  41. new o0.Geometry2D.Float.Vector(points[1].x * size.x, points[1].y * size.y),
  42. new o0.Geometry2D.Float.Vector(points[3].x * size.x, points[3].y * size.y),
  43. new o0.Geometry2D.Float.Vector(points[2].x * size.x, points[2].y * size.y),
  44. size.o0Vector()
  45. )
  46. );
  47. }
  48. ToMode(Mode.InfraredLocate);
  49. }
  50. /// <summary>
  51. /// 传入算法对应的点来设置算法屏幕四边形
  52. /// </summary>
  53. /// <param name="points"></param>
  54. public void QuadUnityVectorListToScreenQuad(List<Vector2> points)
  55. {
  56. if (points != null && points.Count == 4)
  57. {
  58. var size = getUVCCameraInfoSize;
  59. screenIdentification?.SetScreenQuad(
  60. new QuadrilateralInCamera(
  61. new o0.Geometry2D.Float.Vector(points[0].x * size.x, points[0].y * size.y),
  62. new o0.Geometry2D.Float.Vector(points[1].x * size.x, points[1].y * size.y),
  63. new o0.Geometry2D.Float.Vector(points[2].x * size.x, points[2].y * size.y),
  64. new o0.Geometry2D.Float.Vector(points[3].x * size.x, points[3].y * size.y),
  65. size.o0Vector()
  66. )
  67. );
  68. }
  69. ToMode(Mode.InfraredLocate);
  70. }
  71. /// <summary>
  72. /// 自动校准
  73. /// </summary>
  74. public void EnterScreenLocateManualAuto()
  75. {
  76. BtnScreenLocate();
  77. }
  78. /// <summary>
  79. /// 设置Capture值,测试用
  80. /// </summary>
  81. /// <param name="value"></param>
  82. public void SetCapture(int value)
  83. {
  84. Capture = value;
  85. }
  86. /// <summary>
  87. /// 设置Delay值,测试用
  88. /// </summary>
  89. /// <param name="value"></param>
  90. public void SetDelay(int value)
  91. {
  92. Delay = value;
  93. }
  94. /// <summary>
  95. /// 校准点位置同步到[调试面板]
  96. /// </summary>
  97. public void SyncInfraredDemo()
  98. {
  99. if (quadUnityVectorList.Count == 0) return;
  100. // Vector2 texSize = getUVCCameraInfoSize;
  101. Debug.Log("[ScreenLocate] SyncInfraredDemo : " + PrintVector2List(quadUnityVectorList));
  102. //同步到infaredDemo
  103. FindObjectOfType<InfraredDemo>()?.SetLocatePointsToCameraRender(
  104. quadUnityVectorList,
  105. 1,
  106. 1);
  107. }
  108. /// <summary>
  109. /// 校准点位置同步到[手动校准页面]
  110. /// </summary>
  111. public void SyncInfraredScreenPositioningView()
  112. {
  113. if (quadUnityVectorList.Count == 0) return;
  114. //同步位置
  115. FindObjectOfType<InfraredScreenPositioningView>()?.SyncScreenPosition();
  116. }
  117. }