在 Unity 中显示实时摄像机源 [英] Display live camera feed in Unity

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

问题描述

我有一个关于 Unity 的问题.我希望以前没有回答过这个问题.我想将相机(如高清摄像头)连接到我的计算机,视频源应该显示在我的 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天全站免登陆