| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Collections.Generic;
- using Unity.VisualScripting;
- using UnityEngine;
- using UnityEngine.UI;
- using ZIM;
- public class InfraredLocateTest : MonoBehaviour
- {
- public ZIMWebCamera webCamera;
- public List<RawImage> crosshairInCamera;
- public List<Vector2> InfraredLocation { get; private set; }
- public Color[] pixels { get; private set; }
- InfraredLocate infraredLocate;
- // Update is called once per frame
- void Update()
- {
- //WebCamTexture texture = webCamera?.webCamTexture;
- //if (texture == null) return;
- //if (infraredLocate == null)
- // infraredLocate = new InfraredLocate(webCamera);
-
- //if (texture.didUpdateThisFrame) // 检查camera是否更新帧
- //{
- // pixels = texture.GetPixels(); // 从左往右、从下往上
- // InfraredLocation = infraredLocate.Get(pixels);
- // foreach (var i in crosshairInCamera)
- // {
- // i.gameObject.SetActive(false);
- // }
- // for (int i = 0; i < InfraredLocation.Count; i++)
- // {
- // // 检测到光点
- // var posInCanvas = InfraredLocation[i].pixelToLocalPosition_AnchorCenter(webCamera.Size, webCamera.rawImage.rectTransform.rect);
- // crosshairInCamera[i].gameObject.SetActive(true);
- // crosshairInCamera[i].rectTransform.anchoredPosition = posInCanvas;
- // //Debug.Log("location: " + posInCanvas);
- // }
- //if (InfraredLocation.Count == 0)
- //{
- // // 没有检测到亮点
- // crosshairInCamera.gameObject.SetActive(false);
- //}
- //else
- //{
- // // 检测到光点
- // var posInCanvas = ((Vector2)InfraredLocation).pixelToLocalPosition_AnchorCenter(webCamera.Size, webCamera.rawImage.rectTransform.rect);
- // crosshairInCamera.gameObject.SetActive(true);
- // crosshairInCamera.rectTransform.anchoredPosition = posInCanvas;
- // //Debug.Log("location: " + posInCanvas);
- //}
- //}
- }
- }
|