在Unity中显示实时摄像头供稿 [英] Display live camera feed in Unity

查看:443
本文介绍了在Unity中显示实时摄像头供稿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Unity有疑问.我希望以前没有得到答复. 我想将摄像机(如HD cam)连接到我的计算机,并且视频源应该显示在Unity场景中.可以将其想象为一个虚拟电视屏幕,该屏幕实时显示相机所看到的内容.我怎样才能做到这一点? Google没有为我指出正确的方向,但也许我只是无法正确地执行查询;)

I have a question regarding Unity. I hope this hasn't been answered before. I want to connect a Camera (like a HD cam) to my computer and the video feed should be displayed inside my Unity scene. Think of it like a virtual television screen, that displays what the camera is seeing in realtime. How can i do this? Google didn't point me in the right direction, but maybe I'm just unable to get the query right ;)

我希望你明白我要干什么.

I hope you understand what I'm going for.

推荐答案

是的,当然可以,幸运的是,Unity3D实际上非常好地支持它.您可以使用 WebCamTexture 查找网络摄像头并将其渲染为纹理.从那里,您可以选择在3D场景中的任何物体上渲染纹理,当然包括虚拟电视屏幕.

Yes that certainly is possible and luckily for you Unity3D actually supports it quite well out of the box. You can use a WebCamTexture to find the webcam and render it to a texture. From there you can choose to render the texture on anything in the 3D scene, including your virtual television screen of course.

这看起来很容易解释,但是下面的代码应该可以让您入手.

It looks pretty self explanatory but the below code should start you off.

列出并打印出它检测到的已连接设备:

List and print out the connected devices it detects:

var devices : WebCamDevice[] = WebCamTexture.devices;
for( var i = 0 ; i < devices.length ; i++ )
    Debug.Log(devices[i].name);

连接到连接的网络摄像头并将图像数据发送到纹理:

Connect to an attached webcam and send the image data to a texture:

WebCamTexture webcam = WebCamTexture("NameOfDevice");
renderer.material.mainTexture = webcam;
webcam.Play();

这篇关于在Unity中显示实时摄像头供稿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆