赞
踩
- private WebCamTexture cameraTexture;
- private bool isPlay = false;
- private string cameraName;
-
- public int getWidth = 1920;
- public int getHeight = 1080;
-
- IEnumerator CamInput()
- {
- yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
- if (Application.HasUserAuthorization(UserAuthorization.WebCam))
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- cameraName = devices[0].name;
- cameraTexture = new WebCamTexture(cameraName, getWidth, getHeight, 30);
- cameraTexture.Play();
- print("画面得到");
- isPlay = true;
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
上面设置的cameraTexture的长和宽其实并不是一定符合你自己规定的值的。
如果你打印一下
- private void Update()
- {
- if (isPlay)
- {
- print(cameraTexture.width + " " + cameraTexture.height);
- }
- }
会发现,如果你输入定义1400和800,打印结果是1280和720。也就是说,unity对webcamtexture的大小是受相机干扰的。你的摄像头会自动调整你设置的图像的大小。当设置为800 * 600的时候,不同的usb摄像头也许会做出完全不一样的处理,也许按照你的设置获取图像,也许会自动给你调整为640 * 360的大小。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。