首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从Kinect深度流获取像素颜色

从Kinect深度流获取像素颜色
EN

Stack Overflow用户
提问于 2013-01-22 00:44:33
回答 1查看 2.9K关注 0票数 2

我目前在尝试从Kinect Depth Stream中找到特定像素的颜色时遇到了一些困难。下面的代码是我用来计算(100,100)像素颜色的代码。

我有一种感觉,我的逻辑在什么地方有缺陷(可能是在将索引计算到我想要的colorPixels中时)

colorPixels和depthPixels声明如下:

代码语言:javascript
复制
colorFrame.CopyPixelDataTo(colorPixels); //colorPixels is a byte[]
depthFrame.CopyDepthImagePixelDataTo(depthPixels); //depthPixels is a DepthImagePixel[]

我计算深度流中100,100像素的rgb值,如下所示:

代码语言:javascript
复制
DepthImagePoint ballDepthPoint = new DepthImagePoint();
int ballPosX = 100;
int ballPosY = 100;
int blueTotal = 0, greenTotal = 0, redTotal = 0;

ColorImagePoint ballColorPoint;

//build a depth point to translate to a color point
ballDepthPoint.X = ballPosX;
ballDepthPoint.Y = ballPosY;
ballDepthPoint.Depth = this.depthPixels[ballDepthPoint.X * ballDepthPoint.Y].Depth;

//work out the point on the color image from this depth point
ballColorPoint = this.sensor.CoordinateMapper.MapDepthPointToColorPoint(this.sensor.DepthStream.Format, ballDepthPoint, this.sensor.ColorStream.Format);

//extract the rgb values form the color pixels array
blueTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel)];
greenTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 1];
redTotal += (int)colorPixels[(ballColorPoint.X * ballColorPoint.Y * colorFrame.BytesPerPixel) + 2];

System.Console.WriteLine("The ball found is " + redTotal + "," + blueTotal + "," + greenTotal + " which is " + Helper.ColorChooser(redTotal, greenTotal, blueTotal)); 

ColorChooser方法如下:

代码语言:javascript
复制
public static String ColorChooser(int r, int g, int b)
    {

        if (r >= g && r >= b)
        {
            return "RED";
        }
        else if (b >= g && b >= r)
        {
            return "BLUE";
        }
        else
            return "GREEN";
    }

如果您需要更多信息/代码,请让我知道。

非常感谢,

戴夫McB

EN

回答 1

Stack Overflow用户

发布于 2013-01-22 05:09:18

最后,对彩色像素中的像素进行索引的正确方法似乎是:

代码语言:javascript
复制
colorPixels[(ballColorPoint.X * colorFrame.BytesPerPixel) + (ballColorPoint.Y * stride)];

其中:

代码语言:javascript
复制
int stride = colorFrame.BytesPerPixel * colorFrame.Width;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14443302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档