【问题标题】:Selecting a camera and outputting video when connecting multiple cameras in UnityUnity中连接多个摄像头时选择摄像头并输出视频
【发布时间】:2021-08-08 06:52:33
【问题描述】:

我正在尝试通过在 Unity 中连接手部跟踪摄像头设备(Leap Motion:窗口设备管理器列表:0)和网络摄像头(窗口设备管理器列表:1)来显示 AR 视频。

Leap motion 连接使用制造商的 SDK 和包文件,因此无需额外编码即可在 Unity 中连接相机。

当我在 Unity 中连接网络摄像头(窗口设备管理器列表:1)并显示 AR 视频时出现问题。

当以下代码应用于对象时,如果 Leap motion 和 webcam camera 都连接,leap motion 被识别并作为视频输出,并且 webcam camera 的视频输出变得不可能。

如果从PC上拔下跳跃运动后只连接网络摄像头,则网络摄像头摄像头的视频输出是可能的。

我想通过在 Leap motion 和网络摄像头都连接到 PC 的对象上选择网络摄像头(窗口设备管理器列表:1)来输出视频。

由于我是Unity的初学者,我需要在下面的代码中简单地修改一下。

等待帮助。

using UnityEngine;
using System.Collections;
 
public class WebCam : MonoBehaviour {
 
    // Use this for initialization
    void Start () {
        WebCamTexture web = new WebCamTexture(1280,720,60);
        GetComponent<MeshRenderer>().material.mainTexture = web;
        web.Play();
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}

【问题讨论】:

    标签: c# unity3d camera selection leap-motion


    【解决方案1】:

    有一个WebCamTexture的构造函数接受参数

    deviceName:要使用的视频输入设备的名称。

    您可以通过WebCamTexture.devices 列出所有可用设备并获取名称,例如:

    var devices = WebCamTexture.devices;
    var webcamTexture = new WebCamTexture(devices[1].name);
    

    您也许还可以过滤掉您需要的设备,例如

    using System.Linq;
    
    ...
    
    var device = devices.Select(d => d.name).FirstOrDefault(n => !n.Contains("Leap"));
    

    要了解如何调用相机并能够按名称过滤,您可以将它们全部打印出来,例如

    Debug.Log(string.Join("\n", devices.Select(d => d.name)));
    

    理论上,您甚至可以将它们输入下拉列表,让用户在创建 WebCamTexture 之前决定使用哪个设备,那么您根本不必猜测硬编码的名称;)


    另请注意:

    在创建 WebCamTexture 之前调用 Application.RequestUserAuthorization

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      相关资源
      最近更新 更多