2
votes

I'm working a project that about biometric measurement with kinect. I have a Kinect v1 for Xbox. I can get color image and depth image via this kinect. I want to mapping depth value of color image point. Kinect sdk doesnt support CoordinateMapper.MapColorPoint2DepthPoint or space. All coordinate tranformation method is here.All Mapping Functions List

How can I mapping color point to depth point with kinect v1 for xbox. Thanks your answers.

note : Language: C# , Platform: Windows Form

2

2 Answers

1
votes

What you need is the CoordinateMapper.MapDepthFrameToColorFrame method.

The Coordinate Mapping Basics-WPF C# Sample shows how to use this method. You can find some significant parts of the code in the following:

// Intermediate storage for the depth data received from the sensor
private DepthImagePixel[] depthPixels;
// Intermediate storage for the color data received from the camera
private byte[] colorPixels;
// Intermediate storage for the depth to color mapping
private ColorImagePoint[] colorCoordinates;
// Inverse scaling factor between color and depth
private int colorToDepthDivisor;
// Format we will use for the depth stream
private const DepthImageFormat DepthFormat = DepthImageFormat.Resolution320x240Fps30;
// Format we will use for the color stream
private const ColorImageFormat ColorFormat = ColorImageFormat.RgbResolution640x480Fps30;

//...

// Initialization
this.colorCoordinates = new ColorImagePoint[this.sensor.DepthStream.FramePixelDataLength];
this.depthWidth = this.sensor.DepthStream.FrameWidth;
this.depthHeight = this.sensor.DepthStream.FrameHeight;
int colorWidth = this.sensor.ColorStream.FrameWidth;
int colorHeight = this.sensor.ColorStream.FrameHeight;
this.colorToDepthDivisor = colorWidth / this.depthWidth;
this.sensor.AllFramesReady += this.SensorAllFramesReady;

//...

private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e)
{
    // in the middle of shutting down, so nothing to do
    if (null == this.sensor)
    {
        return;
    }

    bool depthReceived = false;
    bool colorReceived = 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;
        }
    }

    using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
    {
        if (null != colorFrame)
        {
            // Copy the pixel data from the image to a temporary array
            colorFrame.CopyPixelDataTo(this.colorPixels);

            colorReceived = true;
        }
    }

    if (true == depthReceived)
    {
        this.sensor.CoordinateMapper.MapDepthFrameToColorFrame(
            DepthFormat,
            this.depthPixels,
            ColorFormat,
            this.colorCoordinates);

        // ...

        int depthIndex = x + (y * this.depthWidth);
        DepthImagePixel depthPixel = this.depthPixels[depthIndex];

        // scale color coordinates to depth resolution
        int X = colorImagePoint.X / this.colorToDepthDivisor;
        int Y = colorImagePoint.Y / this.colorToDepthDivisor;

        // depthPixel is the depth for the (X,Y) pixel in the color frame
    }
}
1
votes

Thanks Vito your fast reply. I solved it Kinect sdk provide to me from depth frame to color frame. I find depth value of image point(x,y) from manuel inverse transaction of depth-color map.

This function return depth value of specific color image point.

public int GetDepthFromColorImagePoint(KinectSensor sensor, DepthImageFormat depthImageFormat, ColorImageFormat colorImageFormat, DepthImagePixel[] depthPixels, int depthWidth, int depthHeight, int colorImageX, int colorImageY)
{
   ColorImagePoint[] color_points = new ColorImagePoint[depthHeight * depthWidth];

   sensor.CoordinateMapper.MapDepthFrameToColorFrame(depthImageFormat, depthPixels, colorImageFormat, color_points);

   int depthIndex = color_points.ToList().FindIndex(p => p.X == colorImageX && p.Y == colorImageY);
      if (depthIndex < 0)
          return -1;
      short depthValue = depthPixels[depthIndex].Depth;
      return depthValue;
}

if you see result of this function , view this gif