Unity3D 设置摄像头的分辨率,比如罗技

怎样知道一款网络摄像头支持的最高分辨率呢?

1. 我们根据该网络摄像头的型号来查其具体参数,我手上有罗技C310罗技C920,C310支持1280x720,C920支持1920x1080,这样在构造WebCamTexture时就可以指定其支持的最大分辨率。

测试用的C#脚本如下:


using UnityEngine;  
using System.Collections;  
  
public class CameraTest : MonoBehaviour {  
  
    private string deviceName;  
    private WebCamTexture tex;  
    private Vector2 resSize = new Vector2(1920,1080);  
    //private Vector2 resSize = new Vector2(640,480);  
    public GameObject plane;  
  
    // Use this for initialization  
    void Start ()   
    {  
        StartCoroutine(InitCamera());  
    }  
      
    // Update is called once per frame  
    void Update () {  
      
    }  
  
    protected IEnumerator InitCamera()  
    {  
        //获取授权  
        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);  
        if (Application.HasUserAuthorization(UserAuthorization.WebCam))  
        {  
            WebCamDevice[] devices = WebCamTexture.devices;  
            Debug.Log( "devices.Length " + devices.Length );  
            if( devices.Length>0 )  
            {  
                deviceName = devices[0].name;  
                Debug.Log( "deviceName " + deviceName );  
                tex = new WebCamTexture(deviceName,(int)resSize.x, (int)resSize.y, 30);  
                Debug.Log( "tex.width " + tex.width );  
                Debug.Log( "tex.height " + tex.height );  
                plane.renderer.material.mainTexture = tex;  
                tex.Play();  
                Debug.Log( "tex.width " + tex.width );  
                Debug.Log( "tex.height " + tex.height );  
            }  
        }  
    }   
}  

2. 如果是不知型号的摄像头,我们可以在WebCamTexture.Play()后,输出WebCamTexture.width() 和 height(),经测试和查看了下官方文档,如果构造函数时输入的分辨率过大,比如我在用C310时,构造函数却指定1920x1080,这样子它就会用最接近的分辨率,其实这时候最接近的分辨率就是其支持的最大分辨率了。实际上C310支持1280x960,超过官方给的数据。

 参考资料:

http://blog.csdn.net/a117653909/article/details/39936419#

http://docs.unity3d.com/ScriptReference/WebCamTexture-ctor.html


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值