# Conversion from color point to depth point[(x,y) -> depth]

• ### Question

• Hello,

From the color point for conversion into depth point tried as below, but could not be retrieved correctly.

Does this approach would be correct?

/// <summary>
/// Convert Color point to Depth point.
/// </summary>
/// <param name = "depthData"> Depth data(size:512x424) </param>
/// <param name = "pt"> On Full HD (x, y) coordinates(size:1920x1080)</param>
/// <returns> Z coordinate(unit:m) </returns>
public double ConvertColorPtToDepthPt(ushort []depthData,System.Windows.Point pt)
{
double dblRet = 0.0;

DepthSpacePoint dsp = new DepthSpacePoint[1920*1080];

if(depthData != null)
{
mKinect.CoordinateMapper.MapColorFrameToDepthSpace(depthData,dsp);

int nColorIdx = (int)(pt.X + pt.Y * 1920);

if(nColorIdx >= 0 && nColorIdx < dsp.Length)
{
float depthX= dsp[nColorIdx].X
,depthY= dsp[nColorIdx].Y;

if(!(double.IsInfinity(depthX) || double.IsInfinity(depthY)))
{
int nDepthIdx = (int)(depth.X + depth.Y * 512);
if(nDepthIdx < 512 * 424)
{
dblRet = depthData[nDepthIdx] * 0.001; // m terms
}
}
}
}

return dblRet;
}

(X, y) of the joint to the argument pt of this function we've pass could not be obtained just as correctly.

/// <summary>
/// Drawing of joint
/// </summary>
/// <param name = "joint"> Joint </param>
/// <param name = "depthData"> Depth data(size:512x424) </param>
private void DrawJoint(Joint joint,ushort []depthData)
{

System.Windows.Point pt = new System.Windows.Point((double)joint.X,(double)joint.Y);

// ↓joint.Z and dblRet does not match !
// Color point to Depth point.
double dblRet = ConvertColorPtToDepthPt(depthData,pt);

…
}

Best Regards.

Y. Iwata

Reference site

・Color point to depth Point and vice-versa
https://social.msdn.microsoft.com/Forums/en-US/89aa1133-96e5-471b-b5c5-7ac919e9239d/color-point-to-depth-point-and-viceversa?forum=kinectv2sdk

Development environment:VS2013(WPF[C#])
Kinect V2 + SDK(Latest)
OpenCV(2.4.10.20150604)

Monday, August 31, 2015 1:54 PM