Cargue una imagen de un solo canal de 16 bits para una textura en Unity3D
– UnityAssets3Free
bienvenido , por aqui Camilo y en esta ocasion os traigo
esta nueva pregunta
Estoy trabajando con un sensor de profundidad (Orbbec Astra Pro) y quiero mostrar la imagen infrarroja en Unity. Los datos que recibo son un ushort[]
(o cualquier otro tipo, que sea mayor de 8 bits).
Para que pueda crear una textura de 16 bits de un solo canal infraredTexture = new Texture2D(infraredFrame.Width, infraredFrame.Height, TextureFormat.R16, false);
pero no sé cómo llenar la textura con los datos infrarrojos como LoadRawTextureData
solo toma uno byte[]
o IntPtr
.
Entonces, al final, me gustaría ver una textura en escala de grises de 16 bits en Unity. ¿Es esto posible? ¡Agradezco anticipadamente!
1 respuesta 1
En una nota general de TextureFormat.R16
Actualmente, este formato de textura solo es útil para código nativo o complementos de tiempo de ejecución, ya que no se admite la importación de texturas a este formato.
Tenga en cuenta que no todas las tarjetas gráficas admiten todos los formatos de textura, utilice SystemInfo.SupportsTextureFormat para comprobarlo.
No tengo una solución directa para si realmente quieres usar un R16
textura de formato excepto serializar de alguna manera los datos para byte[]
por ejemplo usando Buffer.BlockCopy
– NOTA: ¡Ni idea de esto funcionaría!
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();
Nuevamente, no tengo idea si funciona de esta manera.
Sin embargo, creo que simplemente podrías «fingir» en Unity. Si es solo para mostrar la textura de todos modos, puede usar un «normal» RGB24
textura y simplemente asigne sus datos de un solo canal de 16 bits a un color RGB de 24 bits en escala de grises y aplíquelo usando Texture2D.SetPixels
como por ejemplo
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();
nota: si aun no se resuelve tu pregunta por favor dejar un comentario y pronto lo podremos de nuevo , muchas gracias
eso es todo,hasta la proxima