InfraredLocateTest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System.Collections.Generic;
  2. using Unity.VisualScripting;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using ZIM;
  6. public class InfraredLocateTest : MonoBehaviour
  7. {
  8. public ZIMWebCamera webCamera;
  9. public List<RawImage> crosshairInCamera;
  10. public List<Vector2> InfraredLocation { get; private set; }
  11. public Color[] pixels { get; private set; }
  12. InfraredLocate infraredLocate;
  13. // Update is called once per frame
  14. void Update()
  15. {
  16. //WebCamTexture texture = webCamera?.webCamTexture;
  17. //if (texture == null) return;
  18. //if (infraredLocate == null)
  19. // infraredLocate = new InfraredLocate(webCamera);
  20. //if (texture.didUpdateThisFrame) // 检查camera是否更新帧
  21. //{
  22. // pixels = texture.GetPixels(); // 从左往右、从下往上
  23. // InfraredLocation = infraredLocate.Get(pixels);
  24. // foreach (var i in crosshairInCamera)
  25. // {
  26. // i.gameObject.SetActive(false);
  27. // }
  28. // for (int i = 0; i < InfraredLocation.Count; i++)
  29. // {
  30. // // 检测到光点
  31. // var posInCanvas = InfraredLocation[i].pixelToLocalPosition_AnchorCenter(webCamera.Size, webCamera.rawImage.rectTransform.rect);
  32. // crosshairInCamera[i].gameObject.SetActive(true);
  33. // crosshairInCamera[i].rectTransform.anchoredPosition = posInCanvas;
  34. // //Debug.Log("location: " + posInCanvas);
  35. // }
  36. //if (InfraredLocation.Count == 0)
  37. //{
  38. // // 没有检测到亮点
  39. // crosshairInCamera.gameObject.SetActive(false);
  40. //}
  41. //else
  42. //{
  43. // // 检测到光点
  44. // var posInCanvas = ((Vector2)InfraredLocation).pixelToLocalPosition_AnchorCenter(webCamera.Size, webCamera.rawImage.rectTransform.rect);
  45. // crosshairInCamera.gameObject.SetActive(true);
  46. // crosshairInCamera.rectTransform.anchoredPosition = posInCanvas;
  47. // //Debug.Log("location: " + posInCanvas);
  48. //}
  49. //}
  50. }
  51. }