2013-03-01 190 views
1

我们正在尝试使用this American Sign Language dataset。此数据集包含美国手语字母的图片,包括RGB和深度图片。从数据集中读取深度png图像

我从网上下载的链接数据集。 RGB图像看起来很好,但深度图像完全呈黑色。有些事情是错的。

由于所有的数据集大,这需要时间来下载所有的人;我上传一个例子RGB图像和示例深度图像的位置:

An example RGB image An example depth image

由于深度图像应有的深度数据,我希望它有浮动值(他们说,他们使用的Kinect和Kinect提供浮点值)。我如何使用C#读取这些浮点像素?我试过以下内容:

Bitmap bmp = new Bitmap("depth_0_0002.png"); 
int R = bmp.GetPixel(0,0).R; 
int G = bmp.GetPixel(0,0).G; 
int B = bmp.GetPixel(0,0).B; 

但是,我需要漂浮像素,这些是整数,他们有无意义的值。

我需要包括第三方库?

回答

2

我已经尝试过自己。通常深度数据是16位值。 13个高阶比特包含距离,3个低阶比特包含用户分段映射。

用户分割贴图仅在骨架跟踪处于活动状态时生成,我相信这不在您的示例中。虽然rgb值是24位,但它似乎工作。我从分段的手中获得图像。

Bitmap bmpOrg = new Bitmap("bKawM.png"); 
Bitmap bmp = new Bitmap(106, 119); 

for (int i = 0; i < 106;i++) 
{ 
    for (int j = 0; j < 119;j++) 
    { 
     Color rgb = bmpOrg.GetPixel(i, j); 

     int bit24 = (rgb.B << 16 + rgb.G << 8 + rgb.R); 
     int user = bit24 & 0x07; 
     int realDepth = bit24 >> 3; 

     bmp.SetPixel(i, j, Color.FromArgb(realDepth)); 
    } 
} 

pictureBox1.Image = bmp; 

我的输出:

this is what it looks

我用它再次播放。首先,我在Photoshop中增加了亮度和对比度。 因此,如果您不需要以毫米为单位的实际深度值,则rgb值可用。

increased brightness and contrast

然后我试图与WPF从图像获取16位的值,因为图像进行编码的16位灰度。

Stream imageStreamSource = new FileStream("bKawM.png", FileMode.Open, FileAccess.Read, FileShare.Read); 
PngBitmapDecoder decoder = new PngBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); 
BitmapSource bitmapSource = decoder.Frames[0]; 

int height = bitmapSource.PixelHeight; 
int width = bitmapSource.PixelWidth; 
int stride = width * ((bitmapSource.Format.BitsPerPixel + 7)/8); 

byte[] bytes = new byte[height * stride]; 
bitmapSource.CopyPixels(bytes, stride, 0); 

for (int x = 0; x < width; x++) 
{ 
    for (int y = 0; y < height; y++) 
    { 
     byte low = bytes[y * stride + x + 0]; 
     byte high = bytes[y * stride + x + 1]; 

     ushort bit16 = (ushort)((high << 8) | low); 

     int user = bit16 & 0x07; 
     int realDepth = bit16 >> 3; 

    } 
} 

我创建了深度值的新形象,它看起来很奇怪。我没有找到任何信息 图像包含的数据。我不知道它是否包含用户数据(3位),或者深度是否在保存到文件之前以某种方式转换。

+0

我运行了你的代码并生成了相同的输出文件,但是看起来这个输出中没有深度信息。而不是深度信息,它更像是一个二进制。我期待深度图像.. – Sait 2013-03-04 07:50:33

+0

我已经更新了我的答案。希望这有助于.. – bitWorking 2013-03-04 20:34:41

+0

好吧,事实证明,最有可能的是,图像并不包含比我刚开始时想的更多的东西。谢谢你的帮助。 – Sait 2013-03-05 16:53:10