Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从数据集中读取深度png图像_C#_Image_Color Depth - Fatal编程技术网

C# 从数据集中读取深度png图像

C# 从数据集中读取深度png图像,c#,image,color-depth,C#,Image,Color Depth,我们正在尝试使用。该数据集包含美国手语字母的图片,包括RGB和深度图像 我从链接下载了数据集。RGB图像看起来不错,但深度图像是全黑色的。有点不对劲 因为所有的数据集都很大,下载它们需要时间;我正在上传示例RGB图像和示例深度图像: 因为深度图像应该有深度数据,我希望它有浮点值(他们说他们使用了Kinect,Kinect提供浮点值)。如何使用C#读取这些浮点像素?我尝试了以下方法: Bitmap bmp = new Bitmap("depth_0_0002.png"); int R = bm

我们正在尝试使用。该数据集包含美国手语字母的图片,包括RGB和深度图像

我从链接下载了数据集。RGB图像看起来不错,但深度图像是全黑色的。有点不对劲

因为所有的数据集都很大,下载它们需要时间;我正在上传示例RGB图像和示例深度图像:

因为深度图像应该有深度数据,我希望它有浮点值(他们说他们使用了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;
但是,我需要浮点像素,它们是整数,它们有无意义的值


我需要包括第三方库吗?

我自己也尝试过。通常深度数据为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;
Bitmap bmpOrg=新位图(“bKawM.png”);
位图bmp=新位图(106119);
对于(int i=0;i<106;i++)
{
对于(int j=0;j<119;j++)
{
颜色rgb=bmpOrg.GetPixel(i,j);
int bit24=(rgb.b3;
SetPixel(i,j,Color.FromArgb(realDepth));
}
}
pictureBox1.Image=bmp;
我的输出:

我又玩了一遍。首先我在Photoshop中增加了亮度和对比度。 因此,如果不需要以毫米为单位的实际深度值,则rgb值是可用的

然后我尝试使用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;

    }
}
Stream imageStreamSource=new FileStream(“bKawM.png”,FileMode.Open,FileAccess.Read,FileShare.Read);
PngBitmapDecoder decoder=新的PngBitmapDecoder(imageStreamSource,BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.Default);
BitmapSource BitmapSource=解码器。帧[0];
int height=bitmapSource.PixelHeight;
int-width=bitmapSource.PixelWidth;
int stride=width*((bitmapSource.Format.BitsPerPixel+7)/8);
字节[]字节=新字节[高度*步幅];
bitmapSource.CopyPixels(字节,步长,0);
对于(int x=0;x3;
}
}
我用深度值创建了一个新图像,它看起来很奇怪。我找不到任何信息
图像包含哪些数据。我不知道它是否包含用户数据(3位)或者,如果在保存到文件之前以某种方式转换了深度。

我运行了您的代码并生成了相同的输出文件,但是此输出中似乎没有深度信息。与其说是深度信息,不如说更像是二进制信息。我期待的是深度图像。好的,结果很可能是,图像包含的深度不超过这与我一开始的想法正好相反。谢谢你的帮助。@Sait,我今天检查一下。我们如何判断我们正在阅读的是深度信息?我正在使用matplotlib python查看黑色图像,我可以看到手的轮廓。我将鼠标悬停,看到变化的第三个值(除了x,y)看起来像是相对距离。但正如我所想,它也可能是灰色的渐变色。如何判断距离?