Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
semcoded's avatar
semcoded
Honored Guest
11 years ago

IP Camera and 2D Texture

Hello,

I'm using Unity 4.5 and Oculus Rift DK1. My team and I have succeeded in importing a live IP cam view into unity using this code:

using UnityEngine;
using System.Collections;

public class SEMTEX : MonoBehaviour {

public string uri = "http://192.168.1.101/snapshot.cgi";
public string username = "admin";
public string password = "admin";


public Texture2D cam;


public void Start() {
cam=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);
}
}


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

}


The last thing we are trying to get is the Oculus Rift to look through the camera itself. But when we launch the .exe, it seems to override any settings we gave it to use the OVR. Any idea what is happening?

5 Replies

Replies have been turned off for this discussion
  • You can try drawing GUI textures to the left and right eye cameras or, better yet, draw it with OVRGUI.StereoDrawTexture(..). OVRMainMenu does something similar with OVRGUI.DrawStereoBox(..) to draw the FPS and other info to a stereo rectangle. Hope that helps.
  • Hi. I tried to use this code in order to get video from IP camera so I could use it in Unity. However, I get HTTP error 400 (Bad Request). Im using Unity 3D version 4.5.2f1.

    With WebCamTexture I can get video froma web cam, but IP camera seems to be a lot trickier. Any ideas what could be wrong?
  • Does my server feeding the video have to be set up a certain way? I am trying to do this as well but no success so far, also why are you adding a form field 
  • Well this thread is a blast from the past.

    You can certainly download image by image, which is pretty straight forward to code up using a download and Texture2D loading a PNG or JPG.

    But, these days you can use hardware decoding video to play it back instead. You could buy an asset like the fantastic AVPro, or similiar, Or, you could use a native Android Webview to open a website and render streaming videos (however, the current plugins all seem to have disappeared - but it's possible to roll your own using WebChromeClient and native texture into Unity3d).