简体   繁体   English

使用C#进行Kinect v2颜色深度映射

[英]Kinect v2 color depth mapping using C#

I am trying to map the depth map onto to the color space using the coordinateMapper function from the sdk. 我正在尝试使用sdk中的coordinateMapper函数将深度贴图映射到颜色空间。 However, the output I received is not what I expected, it appears to have a smaller aspect ratio and the image seems to be mirrored. 但是,我收到的输出不是我预期的,它似乎具有较小的宽高比​​,并且图像似乎是镜像的。

Below is the code I used: 以下是我使用的代码:

depthWidth = depthFrameDescription.Width;
depthHeight = depthFrameDescription.Height;

var colorDesc = colorFrame.FrameDescription;
int colorWidth = colorDesc.Width;
int colorHeight = colorDesc.Height;

int size = colorWidth * colorHeight;

DepthSpacePoint[] colSpacePoints = new DepthSpacePoint[colorWidth * colorHeight];

using (KinectBuffer depthFrameData = depthFrame.LockImageBuffer())
using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
{
    this.bitmap.Lock();

    if ((colorWidth == this.bitmap.PixelWidth) && (colorHeight == this.bitmap.PixelHeight))
    {
        byte[] colorFrameData = new byte[size * bytesPerPixel];       

        // Map the values here
        ushort [] frameData = new ushort[depthWidth * depthHeight];
        depthFrame.CopyFrameDataToArray(frameData);
        coordinateMapper.MapColorFrameToDepthSpace(frameData, colSpacePoints);

        this.bitmap.WritePixels(new Int32Rect(0, 0, colorWidth, colorHeight), colSpacePoints, colorWidth * bytesPerPixel, 0);
        this.bitmap.AddDirtyRect(new Int32Rect(0, 0, this.bitmap.PixelWidth, this.bitmap.PixelHeight));
    }    
    this.bitmap.Unlock();
}

this.bitmapBackBufferSize = (uint)![enter image description here][1]((this.bitmap.BackBufferStride * (this.bitmap.PixelHeight - 1)) + (this.bitmap.PixelWidth * this.bytesPerPixel));
isBitmapLocked = true;

If you are trying to map the coordinates of the depth frame to the color frame, you are missing one step. 如果您尝试将深度框架的坐标映射到颜色框架,则缺少一步。

Here is a link that probably explains it better that I can: http://www.bryancook.net/2014/03/mapping-between-kinect-color-and-depth.html 这是一个链接,可能更好地解释我可以: http//www.bryancook.net/2014/03/mapping-between-kinect-color-and-depth.html

But in your case when you use 但在您使用的情况下

coordinateMapper.MapColorFrameToDepthSpace(frameData, colSpacePoints);

The output is not to be used how you are using it. 不使用输出如何使用它。 The output to this function contains all the points that exists both in the color space and in the depth space. 此函数的输出包含颜色空间和深度空间中存在的所有点。 So in order to display those, you want to iterate through your colSpacePoints and do something with each results, in the example I linked, it is called _colorSpacePoints so you can look at what he does with it. 所以为了显示这些,你想迭代你的colSpacePoints并对每个结果做一些事情,在我链接的例子中,它被称为_colorSpacePoints,所以你可以看看他用它做了什么。

I was stuck trying to do probably something similar to what you are doing, however after a few days I found how to properly use the mapping. 我被困在尝试做类似于你正在做的事情,但几天后我发现如何正确使用映射。 If you want more help with your problem tell me what you want to display in your WriteableBitmap. 如果您需要有关问题的更多帮助,请告诉我您要在WriteableBitmap中显示的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM