3
我試圖將從Kinect收到的圖像保存爲png。我從包裝中拿出一個kinect樣本,它在兩個平面上顯示深度和顏色圖片,並對其進行修改。我嘗試了不同的方法,例如直接保存color32或將其轉換爲其他紋理,但沒有任何效果。注意我可以在Unity場景的兩個平面上看到兩個圖像。這是我必須保存圖像的代碼。從kinect保存的圖像是黑色
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;
}
我添加三行示例代碼,我通過在更新功能的註釋標記。我也嘗試將更新更改爲LateUpdate,但沒有任何更改。
如果您嘗試記錄來自'Color32 [] src'的任何值,是否會返回預期的顏色值(基本上不是全部0,0,0)? – Serlite
不是所有的都是0。我將紋理(一張圖片和一個深度)映射到兩個平面上,我可以在平面上看到圖像。 – D3GAN
嗯......如何在您通過數組遍歷時記錄檢索的值?您爲TLidx,TRidx,BLidx,BRidx獲得什麼樣的價值?也在0-255之間變化? – Serlite