ScreenLocate.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using ZIM.Unity;
  4. using o0InfraredLocate.ZIM;
  5. /// <summary>
  6. /// JC-补充接口
  7. /// </summary>
  8. public partial class ScreenLocate
  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. var quad = 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. //screenIdentification?.SetScreenQuad(quad);
  45. screenIdentification.QuadManual = quad;
  46. Debug.Log($"[ScreenLocate] 记录手动数据: {quad}");
  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. //自动定位时候,清除一下记录的点
  77. //quadUnityVectorList.Clear();
  78. //InfraredCameraHelper?.InvokeOnUVCPosUpdate(quadUnityVectorList);
  79. BtnScreenLocate();
  80. }
  81. /// <summary>
  82. /// 设置Capture值,测试用
  83. /// </summary>
  84. /// <param name="value"></param>
  85. public void SetCapture(int value)
  86. {
  87. Capture = value;
  88. }
  89. /// <summary>
  90. /// 设置Delay值,测试用
  91. /// </summary>
  92. /// <param name="value"></param>
  93. public void SetDelay(int value)
  94. {
  95. Delay = value;
  96. }
  97. /// <summary>
  98. /// 校准点位置同步到[调试面板]
  99. /// </summary>
  100. public void SyncInfraredDemo()
  101. {
  102. if (quadUnityVectorList.Count == 0) return;
  103. // Vector2 texSize = getUVCCameraInfoSize;
  104. Debug.Log("[ScreenLocate] SyncInfraredDemo : " + PrintVector2List(quadUnityVectorList));
  105. //同步到infaredDemo
  106. FindObjectOfType<InfraredDemo>()?.SetLocatePointsToCameraRender(
  107. quadUnityVectorList,
  108. 1,
  109. 1);
  110. }
  111. /// <summary>
  112. /// 校准点位置同步到[手动校准页面]
  113. /// </summary>
  114. public void SyncInfraredScreenPositioningView()
  115. {
  116. if (quadUnityVectorList.Count == 0) return;
  117. //同步位置
  118. FindObjectOfType<InfraredScreenPositioningView>()?.SyncScreenPosition();
  119. }
  120. }