Unity3d 从kinect保存的图像为黑色

Unity3d 从kinect保存的图像为黑色,unity3d,kinect,unity5,texture2d,Unity3d,Kinect,Unity5,Texture2d,我试图将从Kinect接收到的图像保存为png。我从软件包中挑选了一个kinect示例,它在两个平面上显示深度和彩色图片,并对它们进行了修改。我尝试了不同的方法,如直接保存颜色32或将其转移到另一个纹理,但都不起作用。注意,我可以看到Unity场景中两个平面上显示的两个图像。这是我必须保存图像的代码 void Update () { if (kinect.pollColor()) { tex.SetPixels32(mipmapImg(kinect.getCol

我试图将从Kinect接收到的图像保存为png。我从软件包中挑选了一个kinect示例,它在两个平面上显示深度和彩色图片,并对它们进行了修改。我尝试了不同的方法,如直接保存颜色32或将其转移到另一个纹理,但都不起作用。注意,我可以看到Unity场景中两个平面上显示的两个图像。这是我必须保存图像的代码

void Update () {

    if (kinect.pollColor())
    {
        tex.SetPixels32(mipmapImg(kinect.getColor(),640,480));
        // Code by me to save the image
        byte[] bytes = tex.EncodeToPNG();
        File.WriteAllBytes("screenshots/testscreen-" + imageCount + ".png", bytes);
        imageCount++;
        //
        tex.Apply(false);
    }
}

private Color32[] mipmapImg(Color32[] src, int width, int height)
{
    int newWidth = width / 2;
    int newHeight = height / 2;
    Color32[] dst = new Color32[newWidth * newHeight];
    for(int yy = 0; yy < newHeight; yy++)
    {
        for(int xx = 0; xx < newWidth; xx++)
        {
            int TLidx = (xx * 2) + yy * 2 * width;
            int TRidx = (xx * 2 + 1) + yy * width * 2;
            int BLidx = (xx * 2) + (yy * 2 + 1) * width;
            int BRidx = (xx * 2 + 1) + (yy * 2 + 1) * width;
            dst[xx + yy * newWidth] = Color32.Lerp(Color32.Lerp(src[BLidx],src[BRidx],.5F),
                                                   Color32.Lerp(src[TLidx],src[TRidx],.5F),.5F);
        }
    }
    return dst;
}
void更新(){
if(kinect.pollColor())
{
tex.SetPixels32(mipmapImg(kinect.getColor(),640480));
//由我编写代码以保存图像
byte[]bytes=tex.EncodeToPNG();
writealBytes(“屏幕截图/testscreen-”+imageCount+“.png”,字节);
imageCount++;
//
tex.Apply(假);
}
}
专用Color32[]mipmapImg(Color32[]src,int-width,int-height)
{
int newWidth=宽度/2;
int newHeight=高度/2;
Color32[]dst=newcolor32[newWidth*newHeight];
for(int-yy=0;yy

我在示例代码中添加了三行代码,并用Update函数中的注释进行了标记。我还尝试将更新更改为最新更新,但没有任何更改

kinect示例代码正在创建如下纹理:

tex = new Texture2D(320,240,TextureFormat.ARGB32,false);
将其更改为:

tex = new Texture2D(320,240,TextureFormat.RGB24,false);
解决了这个问题。
在本文中,它声称EncodeToPNG函数将在ARGB32和RGB24上工作,但似乎情况并非如此

如果您尝试记录
Color32[]src
中的任何值,是否会返回预期的颜色值(基本上不都是0,0,0)?不,不都是0。我将纹理(一张图片和一个深度)映射到两个平面上,我可以看到平面上的图像。嗯……在遍历数组时记录要检索的值如何?TLidx、TRidx、BLidx、BRidx的值范围是多少?也在0-255之间变化?@Serlite值不在0-255之间。我得到这样的东西:247040 247041 247680 247681。