123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
-
- using UnityEngine;
- using UnityEngine.UI;
- namespace NRKernal.NRExamples
- {
-
- [HelpURL("https://developer.nreal.ai/develop/unity/rgb-camera")]
- public class CameraYUVCaptureController : MonoBehaviour
- {
-
- public RawImage CaptureImage;
-
- public Text FrameCount;
-
-
- private NRRGBCamTextureYUV YuvCamTexture { get; set; }
- void Start()
- {
- YuvCamTexture = new NRRGBCamTextureYUV();
- BindYuvTexture(YuvCamTexture.GetTexture());
- YuvCamTexture.Play();
- }
-
- void Update()
- {
- if (YuvCamTexture == null)
- {
- return;
- }
- FrameCount.text = YuvCamTexture.FrameCount.ToString();
- }
-
- public void Play()
- {
- if (YuvCamTexture == null)
- {
- YuvCamTexture = new NRRGBCamTextureYUV();
- }
- YuvCamTexture.Play();
-
-
- BindYuvTexture(YuvCamTexture.GetTexture());
- }
-
-
- private void BindYuvTexture(NRRGBCamTextureYUV.YUVTextureFrame frame)
- {
- CaptureImage.enabled = true;
- CaptureImage.material.SetTexture("_MainTex", frame.textureY);
- CaptureImage.material.SetTexture("_UTex", frame.textureU);
- CaptureImage.material.SetTexture("_VTex", frame.textureV);
- }
-
- public void Pause()
- {
- YuvCamTexture?.Pause();
- }
-
- public void Stop()
- {
- YuvCamTexture?.Stop();
- YuvCamTexture = null;
- CaptureImage.enabled = false;
- }
-
- void OnDestroy()
- {
- YuvCamTexture?.Stop();
- YuvCamTexture = null;
- }
- }
- }
|