UnityでのWebカメラ

Unityでカメラを起動する
まずCreate→3DObjectからPlaneを選択し板を作成
する.この板をカメラ画像を映すためのスクリーンに
する.
public class WebCameraController : MonoBehaviour
{
public int Width = 1920;
public int Height = 1080;
public int FPS = 30;
void Start ()
{
WebCamDevice[] devices = WebCamTexture.devices;
//有効なデバイスのリストを取得する
for (var i = 0; i < devices.Length; i++)
{
Debug.Log (devices [i].name);
}
WebCamTexture webcamTexture = new WebCamTexture(devices[0].name, Width,
Height, FPS);
GetComponent<Renderer> ().material.mainTexture = webcamTexture;
webcamTexture.Play();
}
}
1. WebCamTexture.devices でデバイス上にあるカメラを全て取得
2. 使用するカメラの名前、解像度、FPS を WebCamTexture に渡す
3. オブジェクトのテクスチャーに WebCamTexture を渡す
4. Play メソッドを呼ぶ
●
●
●
カメラを扱うには WebCamTexture を利用すると
簡単に表示できる。WebCam と名前が付いては
いるが Android 等のカメラも普通に使える。
WebCamTexture.devices はカメラが複数ある場
合に選択するといった場合に使用するので一つし
か使わないなら無くても良い。
RealSenseはWebカメラとして使える
●
参考
http://loumo.jp/wp/archive/20150414000004/