0

我是 kinect 编程的新手,我正在使用 kinect 和 opencv 进行球跟踪。我们都知道 kinect 提供深度数据,代码如下:

DepthImagePoint righthandDepthPoint = 
    sensor.CoordinateMapper.MapSkeletonPointToDepthPoint
    (
        me.Joints[JointType.HandRight].Position, 
        DepthImageFormat.Resolution640x480Fps30
    );

double rightdepthmeters = (righthandDepthPoint.Depth);

使用这个,我可以MapSkeletonPointToDepthPoint()通过指定关节类型来获得右手的深度。

是否可以通过在图像中指定位置来获取其他对象的深度?给定坐标..我想获得该坐标中对象的深度?

4

1 回答 1

0

从 Kinect SDK 拉取深度数据可以从DepthImagePixel结构中提取。

下面的示例代码循环遍历整个DepthImageFrame以检查每个像素。如果您希望查看特定坐标,请删除for循环并将 and 设置xy特定值。

// global variables

private const DepthImageFormat DepthFormat = DepthImageFormat.Resolution320x240Fps30;
private const ColorImageFormat ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;

private DepthImagePixel[] depthPixels;

// defined in an initialization function

this.depthWidth = this.sensor.DepthStream.FrameWidth;
this.depthHeight = this.sensor.DepthStream.FrameHeight;

this.depthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength];

private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
{
    if (null == this.sensor)
        return;

    bool depthReceived = false;

    using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
    {
        if (null != depthFrame)
        {
            // Copy the pixel data from the image to a temporary array
            depthFrame.CopyDepthImagePixelDataTo(this.depthPixels);

            depthReceived = true;
        }
    }

    if (true == depthReceived)
    {
        // loop over each row and column of the depth
        for (int y = 0; y < this.depthHeight; ++y)
        {
            for (int x = 0; x < this.depthWidth; ++x)
            {
                // calculate index into depth array
                int depthIndex = x + (y * this.depthWidth);

                // extract the given index
                DepthImagePixel depthPixel = this.depthPixels[depthIndex];

                Debug.WriteLine("Depth at [" + x + ", " + y + "] is: " + depthPixel.Depth);
            }
        }
    }
}
于 2013-02-25T16:39:01.787 回答