unity-game-engine - 在 Unity 中获取英特尔实感深度流

标签 unity-game-engine textures intel depth realsense

我目前正在尝试将新的实感一代(D435,SDK2)的深度流作为Unity中的Texture2D获取。我可以轻松地将常规 RGB 流作为 WebCamTexture 访问,当我尝试获取深度流时,出现此错误:

Could not connect pins - RenderStream()

Unity 可以识别深度相机,但无法显示它。

我还尝试使用 Unity Wrapper 的预制件,但它们并不真正适合我的项目。如果我使用预制件,我可以将数据获取到 R16 纹理。有谁知道如何获取图像中某个点的深度信息(GetPixel() 不适用于 R16 纹理...)?我更喜欢获得 WebCamTexture 流,如果这不起作用,我必须以不同的方式保存信息...

最佳答案

为了获取深度数据,我所做的是创建我自己的继承自 RawImage 的类。我使用自定义类作为深度渲染流的目标,并从类中的纹理组件获取图像。

Binding to custom class

就我而言,我想将 16 位深度数据转换为 8 位 pr channel rgb pgn,以便我可以将其导出为灰度图像。这是我解析图像数据的方法:

byte[] input = texture.GetRawTextureData();
        //create array of pixels from texture 
        //remember to convert to texture2D first
    Color[] pixels = new Color[width*height];

    //converts R16 bytes to PNG32
    for(int i = 0; i < input.Length; i+=2)
    {

        //combine bytes into 16bit number
        UInt16 num = System.BitConverter.ToUInt16(input, i);
        //turn into float with range 0->1
        float greyValue = (float)num / 2048.0f;

        alpha = 1.0f;

        //makes pixels outside measuring range invisible
        if (num >= 2048 || num <= 0)
            alpha = 0.0f;

        Color grey = new Color(greyValue, greyValue, greyValue, alpha);

            //set grey value of pixel based on float
        pixels.SetValue(grey, i/2);
    }

要获取像素,您只需访问新的像素数组即可。

关于unity-game-engine - 在 Unity 中获取英特尔实感深度流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50945802/

相关文章:

unity-game-engine - Unity 2D Android - 将对象限制在屏幕内

unity-game-engine - 为什么我添加 urp 包后我的天空盒就消失了?

ios - 如何在 Sprite Kit 中预加载纹理?

c++ - 纹理平面上的 OpenGL 光照不工作

optimization - GLSL-是否优化了纹理查找?

ios - Mac 上的 Visual Studio for mac 是否与 Unity (IDE) 配合良好?

c# - Unity3D : (Python.net) PythonException: ModuleNotFoundError

linux - 更改intel parallel Studio 2018安装目录

c++ - 从 PXCImage 获取像素值到二维数组

android - 在 INTEL Android (Android-x86) 上安装 Flash 或 AIR?