Unity3D IP摄像头

时间:2014-09-30 11:24:47

标签: unity3d ip-camera

我使用Marmitek IP RoboCam 641将视频输入导入统一。我使用不断刷新的快照来更新屏幕上的GUI.DrawTexture。然而,我最近从Velleman无线ip彩色相机切换到Marmitek。现在我的快照只刷新一次或两次,然后停止并发出此错误:

UnityException:Recv失败:连接已重置 SEMTEX + c__Iterator0.MoveNext()(在Assets / Scripts / SEMTEX.cs:37)

这是我的代码:

using UnityEngine;
using System.Collections;

public class SEMTEX : MonoBehaviour {

//public string uri = "http://192.168.1.101/snapshot.cgi";//velleman
public string uri = "http://192.168.1.30/cgi/jpg/image.cgi";//marmitek
public string username = "admin";
public string password = "admin";
int calc = 0;


Texture2D cam;
Texture2D cam2;


public void Start() {
    cam=new Texture2D(1, 1, TextureFormat.RGB24, true);
    StartCoroutine(Fetch());
    cam2=new Texture2D(1, 1, TextureFormat.RGB24, true);
    StartCoroutine(Fetch());
}


public IEnumerator Fetch() {
    while(true) {
        Debug.Log("fetching... "+Time.realtimeSinceStartup);

        WWWForm form = new WWWForm();
        form.AddField("dummy", "field");    // required by WWWForm
        WWW www = new WWW(uri, form.data, new System.Collections.Generic.Dictionary<string,string>() {  // using www.headers is depreciated by some odd reason
            {"Authorization", "Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(username+":"+password))}
        });
        yield return www;

        if(!string.IsNullOrEmpty(www.error))
            throw new UnityException(www.error);

        www.LoadImageIntoTexture(cam);
        www.LoadImageIntoTexture(cam2);
    }
}


public void OnGUI() {
    GUI.DrawTexture(new Rect(0,0,Screen.width/2,Screen.height), cam);

    calc = (Screen.width/2-100);

    GUI.DrawTexture(new Rect(calc,0,Screen.width/2,Screen.height), cam2);
    Debug.Log (Screen.width);
}

有没有人对我的错误有任何想法?

0 个答案:

没有答案