本文介绍了将深度转换为相机然后转换为色彩空间时,CoordinateMapper无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

Hello everyone,

我正在尝试将深度点映射到我的Kinect中深度帧数据的已定义部分中的颜色空间V2。我正在使用CoordinateMapper在各个空格之间进行转换。



以下是代码的片段 -

I am trying to map depth point to color space in the defined portion of the depth frame data in my Kinect v2. I am using CoordinateMapper for conversion between various spaces.

Below is the snippet of the code-

private void KinectMultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
{
    var reference = e.FrameReference.AcquireFrame();
    ColorFrame ColorFrame = reference.ColorFrameReference.AcquireFrame();
    DepthFrame DepthFrame = reference.DepthFrameReference.AcquireFrame();

    if (ColorFrame != null && DepthFrame != null)//Do not proceed, if any frame is expired
    {
        ColorFrame.CopyConvertedFrameDataToArray(ColorFramePixels, ColorImageFormat.Bgra);
        Image<Bgra, byte> ColorFrameImage = GetBgraImageFromBytes(colorFrameWidth, colorFrameHeight, colorFramePixels);

        DepthFrame.CopyFrameDataToArray(DepthFrameData);

        CoordinateMapper.MapColorFrameToDepthSpace(DepthFrameData, DepthSpacePoints);

        for (int index = 0; index < DepthFrameData.Length; index++)
        {
            ushort depth = DepthFrameData[index];// Get the depth for current pixel

            if (depth > depthMinReliableDistance && depth < depthMaxReliableDistance)//Ignore outside points
            {
                CameraSpacePoint point = CoordinateMapper.MapDepthPointToCameraSpace(DepthSpacePoints[i], depth);
                //Some processing on CameraSpacePoint are cropped while putting the code here
                ColorSpacePoint colorSpacePoint = CoordinateMapper.MapCameraPointToColorSpace(point);
                DrawMarkInImage(ColorFrameImage, colorSpacePoint);
            }
        }
        ColorImgBox.Image = ColorFrameImage;// See the image
    }

    if (ColorFrame != null) ColorFrame.Dispose();
    if (DepthFrame != null) DepthFrame.Dispose();
}

//Convert the bytes into image using EmguCV
Image<Bgra, byte> GetBgraImageFromBytes(int Width, int Height, byte[] Pixels)
{
    Image<Bgra, byte> Image = new Image<Bgra, byte>(Width, Height);
    Image.Bytes = Pixels;
    return Image
}

//Draw circle (Just for debugging purpose)
void DrawMarkInImage(Image<Bgra, byte> ColorFrameImage, ColorSpacePoint ColorSpacePoint)
{
    Point CircleCenter = new Point((int)ColorSpacePoint.X, (int)ColorSpacePoint.Y)
    ColorFrameImage.Draw(new CircleF(CircleCenter, 2), new Bgra(0, 255, 255, 255), 1);
}


但是,当我尝试将深度直接转换为色彩空间时,效果很好。但由于我正在对CameraSpacePoint进行处理,我需要在上面工作。



有人请告诉我错误在哪里以及如何解决。

However, when I tried to converting the depth directly to color space, it works well. But since I am doing processing over CameraSpacePoint, I need to make above working.

Somebody please tell me where is the error and how to resolve it.

推荐答案

因为坐标映射结果只是一个查找表,你需要确保x,y值落入一个范围或在颜色框架中有一个有效的点。您是否检查了.x / .y属性的界限(ColorSpacePoint colorSpacePoint =
CoordinateMapper.MapCameraPointToColorSpace(point);)

Because the coordinate mapped result is just a lookup table, you need to ensure the x,y value falls into a range or has a point in the color frame that is valid. Did you check the bounds of the .x/.y properties for this(ColorSpacePoint colorSpacePoint = CoordinateMapper.MapCameraPointToColorSpace(point);)


这篇关于将深度转换为相机然后转换为色彩空间时,CoordinateMapper无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 02:44