TestRGB.cs 982 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TestRGB : MonoBehaviour
  6. {
  7. public int index;
  8. int w = 1280;
  9. int h = 720;
  10. WebCamTexture RGBCamTexture;
  11. // Start is called before the first frame update
  12. void Start()
  13. {
  14. WebCamDevice[] devices = WebCamTexture.devices;
  15. if (devices.Length == 0)
  16. {
  17. Debug.Log("No webcam devices found.");
  18. return;
  19. }
  20. // 使用第一个可用的摄像头设备(你可以根据需要选择其他设备)
  21. RGBCamTexture = new WebCamTexture(devices[index].name, w, h, 30);
  22. Debug.Log("开启摄像头" + devices[index].name);
  23. // 开始摄像头捕捉
  24. RGBCamTexture.Play();
  25. if (this.GetComponent<RawImage>() != null)
  26. {
  27. this.GetComponent<RawImage>().texture = RGBCamTexture;
  28. this.GetComponent<RawImage>().transform.localEulerAngles = new Vector3(0, 0, 0);
  29. }
  30. }
  31. }