0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unity備忘録 Macのカメラで写した映像を表示する方法

Posted at

Macのカメラで写した映像をUnity内でリアルタイム表示する方法ですが、
非常に簡単にできたので共有いたします。

適当にクラスを作成し、下記のコードをコピペして下さい。
ここではWebCam.csとしました。

using UnityEngine;
using UnityEngine.UI;

public class WebCam : MonoBehaviour {

    [SerializeField] RawImage rawImage;
    WebCamTexture webCamTexture;

    void Start ()  {
        webCamTexture = new WebCamTexture(512, 512, 60);
        rawImage.texture = this.webCamTexture;
        webCamTexture.Play();
    }
}

次に、Unityのヒエラルキー上で右クリックメニューから、UI > Raw Imageを選択。
作成されたRawImageにWebCam.csを付けて、
SelializeFieldの空欄にRawImageをクリックアンドドラッグでセットしてください。
スクリーンショット 2022-04-05 1.42.35.png

Unityを実行すると、下記のように映す事ができます。
スクリーンショット 2022-04-05 1.46.44.png

WebCam.csでは60fpsで滑らかに撮影するようにしていますが、60→30に変更すると30fpsに設定できます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?