首页 > 解决方案 > 将视频从 PC 直播到 HoloLens 时如何提高 HoloLens 的性能?

问题描述

我正在开发一个 HoloLens 项目,并希望添加一个功能,将屏幕截图从我的 PC 实时流式传输到 HoloLens。幸运的是,我找到了一个存储库https://gist.github.com/jryebread/2bdf148313f40781f1f36d38ada85d47,非常有帮助。我在客户端修改了一点 Python 代码,以便在我的 PC 上获取屏幕截图,并将每一帧连续发送到 HoloLens。但是,HoloLens 在图像接收器运行时表现不佳,即使是可手动拖动的立方体也无法平滑移动,并且整个帧率下降。

我曾尝试在 Unity 中使用 Holographic Remoting Player,例如https://docs.microsoft.com/en-us/windows/mixed-reality/holographic-remoting-player。这样,我只需要在本地读取我 PC 的屏幕截图,并将整个渲染帧发送到 HoloLens。但是,当我播放 Unity 场景时,包含屏幕截图的原始图像会显示在 Unity 中,但不会显示在 HoloLens 上。

我使用 IEnumerator load_image() 和 StartCoroutine("load_image"); 从我的电脑加载图像。我用来加载图像并在 UI-RawImage 上显示的代码是

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;

public class LiveScreen : MonoBehaviour {

    public RawImage rawImage;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        StartCoroutine("load_image");
    }

    IEnumerator load_image()
    {
        string[] filePaths = Directory.GetFiles(@"G:\Files\Pyfiles\", "*.jpg");                  // get every file in chosen directory with the extension.png
        WWW www = new WWW("file://" + filePaths[0]);                                    // "download" the first file from disk
        yield return www;                                                               // Wait unill its loaded
        Texture2D new_texture = new Texture2D(320, 180);                                // create a new Texture2D (you could use a gloabaly defined array of Texture2D )
        www.LoadImageIntoTexture(new_texture);                                          
        rawImage.texture = new_texture;
        new_texture.Apply();
    }
}

谁能给我建议如何提高 HoloLens 上 APP 的性能,或者我是否可以为这个项目使用 HoloLens 的远程渲染?

提前致谢。

标签: c#uwphololens

解决方案


load_image() 中的过程理论上应该可以工作。

但是在每个 update() 帧循环中启动一个协程是一个非常糟糕的做法。最好启动一个协程并使用带有 WaitForSecond() 中断的永无止境的循环。通过这种方式,您可以尝试全息透镜可以处理的最大重复率是多少。

void Start () {
     StartCoroutine(StartImageLoading());
 }

 IEnumerator StartImageLoading () {
     while(true){ // This creates a never-ending loop
         yield return new WaitForSeconds(1);
         LoadImage();
         // If you want to stop the loop, use: break;
     }
 }

您也应该在 load_images() 中优化您的代码。如果要显示一张图像,只需从磁盘加载一个文件。那要快得多!


推荐阅读