简体   繁体   English

Kinect v2 红外传感器和 RGB 图像的对齐总是略微关闭

[英]Kinect v2 Alignment of Infrared Sensor & RGB Image always slightly off

I'm using the official Kinect SDK 2.0 and Emgu CV in order to recognize the colors of a Rubik's Cube.我使用官方 Kinect SDK 2.0 和 Emgu CV 来识别魔方的颜色。

在此处输入图片说明

At first I use Canny Edge Extraction on the Infrared Camera since it handles different lightning conditions better than the RGB Camera and is much better to detect contours.起初我在红外相机上使用 Canny 边缘提取,因为它比 RGB 相机更好地处理不同的闪电条件,并且更好地检测轮廓。

Then I use this code to convert the coordinates of the infrared sensor to the ones of the RGB camera.然后我使用此代码将红外传感器的坐标转换为 RGB 相机的坐标。 As you can see the in the picture they are still off from what I am looking for.正如您在图片中看到的那样,它们仍然与我要寻找的东西相去甚远。 Since I already use the official KinectSensor.CoordinateMapper.MapDepthFrameToColorSpace I don't know how else I can improve the situation.由于我已经使用了官方的KinectSensor.CoordinateMapper.MapDepthFrameToColorSpace我不知道我还能如何改善这种情况。

using (var colorFrame = reference.ColorFrameReference.AcquireFrame())
using (var irFrame = reference.InfraredFrameReference.AcquireFrame())
{
    if (colorFrame == null || irFrame == null)
        return;

    // initialize depth frame data 
    FrameDescription depthDesc = irFrame.FrameDescription;

    if (_depthData == null)
    {
        uint depthSize = depthDesc.LengthInPixels;
        _depthData = new ushort[depthSize];
        _colorSpacePoints = new ColorSpacePoint[depthSize];

         // fill Array with max value so all pixels can be mapped
         for (int i = 0; i < _depthData.Length; i++)
         {
             _depthData[i] = UInt16.MaxValue;
         }
         // didn't work so well with the actual depth-data
         //depthFrame.CopyFrameDataToArray(_depthData);

        _sensor.CoordinateMapper.MapDepthFrameToColorSpace(_depthData, _colorSpacePoints);
    }
}

This is a helper-function I created in order to convert Point-Arrays in Infrared-Space to Color-Space这是我创建的一个辅助函数,用于将红外空间中的点阵列转换为颜色空间

public static System.Drawing.Point[] DepthPointsToColorSpace(System.Drawing.Point[] depthPoints, ColorSpacePoint[] colorSpace){
        for (int i = 0; i < depthPoints.Length; i++)
        {
            // 512 is the width of the depth/infrared image
            int index = 512 * depthPoints[i].Y + depthPoints[i].X;

            depthPoints[i].X = (int)Math.Floor(colorSpace[index].X + 0.5);
            depthPoints[i].Y = (int)Math.Floor(colorSpace[index].Y + 0.5);
        }
        return depthPoints;
    }

We can solve this problem by transforming infrared image coordinates to color image coordinates with 2 quadrilateral mapping.我们可以通过将红外图像坐标转换为具有 2 个四边形映射的彩色图像坐标来解决这个问题。

A quadrilateral Q(x1,y1,x2,y2,x3,y3,x4,y4) in an infrared image, similarly, it's mapping quadrilateral Q'(x1',y1',x2',y2',x3',y3',x4',y4') in the corresponding color image.红外图像中的四边形Q(x1,y1,x2,y2,x3,y3,x4,y4)类似地,它映射四边形Q'(x1',y1',x2',y2',x3',y3',x4',y4')在相应的彩色图像中。

We can write the above mapping in form of equation as follows:我们可以将上述映射写成等式如下:

Q'= Q*A

where, A is a 3 X 3 matrix with coefficients a11, a12, a13, a21,.., a33;其中,A 是一个 3 X 3 矩阵,系数为 a11、a12、a13、a21、..、a33;

The formula to obtain the coefficients are listed as follows:获得系数的公式如下:

x1=173; y1=98; x2=387; y2=93; x3=395; y3=262; x4=172; y4=264;  
x1p=787; y1p=235;  x2p=1407; y2p=215; x3p=1435; y3p=705;  x4p=795; y4p=715; 
tx=(x1p-x2p+x3p-x4p)*(y4p-y3p)-(y1p-y2p+y3p-y4p)*(x4p-x3p);
ty=(x2p-x3p)*(y4p-y3p)-(x4p-x3p)*(y2p-y3p);
a31=tx/ty;
tx=(y1p-y2p+y3p-y4p)*(x2p-x3p)-(x1p-x2p+x3p-x4p)*(y2p-y3p);
ty=(x2p-x3p)*(y4p-y3p)-(x4p-x3p)*(y2p-y3p);
a32=tx/ty;
a11=x2p-x1p+a31*x2p;
a12=x4p-x1p+a32*x4p;
a13=x1p;
a21=y2p-y1p+a31*y2p;
a22=y4p-y1p+a32*y4p;
a23=y1p;
a33=1.0;

Its because its not the same camera the camera that retrieves the depth data and the one that retrieves color data.这是因为检索深度数据的相机和检索颜色数据的相机不是同一个相机。 So you should apply a correction factor to displace the depth data.因此,您应该应用校正因子来置换深度数据。 Its a factor that is almost constant but its related to the distance.它是一个几乎恒定的因素,但与距离有关。 I've got no code for you, but its something you can calculate yourself.我没有给你的代码,但你可以自己计算。

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

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