我是与深度传感器(Orbbec )工作,并希望显示红外图像在团结。我收到的数据是一个ushort[] (或任何其他类型,大于8位)。
因此,我可以创建一个单一通道16位纹理infraredTexture = new Texture2D(infraredFrame.Width, infraredFrame.Height, TextureFormat.R16, false);,但我不知道如何填充纹理的红外数据,因为LoadRawTextureData只需要一个byte[]或IntPtr。
所以,在最后,我想看到一个16位灰度纹理在团结。这有可能吗?提前谢谢你!
发布于 2021-09-13 15:15:10
一般情况下,来自TextureFormat.R16的注释
目前,这种纹理格式只对运行时或本机代码插件有用,因为不支持该格式的纹理导入。
注意,并不是所有的显卡都支持所有的纹理格式,请使用SystemInfo.SupportsTextureFormat进行检查。
我没有一个直接的解决方案,因为如果您真的想要使用R16格式的纹理,除非以某种方式将数据序列化成byte[],例如使用Buffer.BlockCopy -注意:根本不知道这会有什么用!
ushort[] yourData = // wherever you get this from;
byte[] byteData = new byte[sizeof(ushort) * yourData.Length];
// On memory level copy the bytes from yourData into byteData
Buffer.BlockCopy(yourData, 0, byteData, 0, byteData.Length);
infraredTexture = new Texture2D(infraredFrame.Width, infraredFrame.Height, TextureFormat.R16, false);
infraredTexture.LoadRawTextureData(byteData);
infraredTexture.Apply();同样,也不知道它是否会那样工作。
然而,我认为你可以简单地在“团结”中“假装”。如果它只是为了显示纹理,那么您可以使用“普通”RGB24纹理,只需将16位单通道数据映射为灰度24位RGB颜色,然后使用Texture2D.SetPixels进行应用。
ushort[] yourData = // wherever you get this from;
var pixels = new Color[yourData.Length];
for(var i = 0; i < pixels.Length; i++)
{
// Map the 16-bit ushort value (0 to 65535) into a normal 8-bit float value (0 to 1)
var scale = (float)yourData[i] / ushort.MaxValue;
// Then simply use that scale value for all three channels R,G and B
// => grey scaled pixel colors
var pixel = new Color(scale, scale, scale);
pixels[i] = pixel;
}
infraredTexture = new Texture2D(infraredFrame.Width, infraredFrame.Height, TextureFormat.RGB24, false);
// Then rather use SetPixels to apply all these pixel colors to your texture
infraredTexture.SetPixels(pixels);
infraredTexture.Apply();https://stackoverflow.com/questions/69164405
复制相似问题