获取其他对象的深度Kinect



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

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

使用这个,我可以通过指定jointtype来使用函数MapSkeletonPointToDepthPoint()来获得右手的深度。。

是否可以通过在图像中指定位置来获得其他对象的深度?给定坐标。。我想得到物体在那个坐标系中的深度?

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

下面的示例代码循环通过整个DepthImageFrame来检查每个像素。如果要查看特定坐标,请删除for循环,并将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);
            }
        }
    }
}

相关内容

  • 没有找到相关文章

最新更新