Kinect Sdk 2.0正确映射坐标
本文关键字:映射 坐标 Sdk Kinect | 更新日期: 2023-09-27 18:03:36
我希望能够正确地映射坐标,以便在我的手在InkCanvas上移动时产生一条线。
我目前使用的是这样的深度空间点:
DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(SkeletonPosition);
jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
对于我的映射,我使用这个:
/*Use these floats * 1000 to let the user draw on the Canvas*/
float XSP = joints[JointType.HandRight].Position.X * 1000;
float YSP = joints[JointType.HandRight].Position.Y * 1000;
/*Current Point is = Right Hand Floats * 1000*/
currentPoint = new Point(XSP, YSP);
/*Always add 0.1 to the new point to let the user draw, this will technically give a continous line effect as it draws every time the hand moves at a difference of 0.1*/
nextPoint = new Point(XSP + 0.1, YSP + 0.1);
/*Feed the Points into the function, Call while Right hand is Tracked*/
this.Paint(currentPoint, nextPoint, PaintSurface);
现在我可以在屏幕上绘制线条,但是它不能正确映射到我的右手所在的位置,我必须乘以1000才能看到画布上的线条,我做错了什么?我如何纠正这个问题?这是我的Paint Function:
/*Function to Paint/Draw on the Screen*/
public void Paint(Point startPoint, Point nextPoint, InkCanvas inkcanvas)
{
Line line = new Line(); //New Line
/*If Co-ords are equal to 0,0 reset them*/
if (currentPoint.X == 0 && currentPoint.Y == 0)
{
currentPoint = new Point();
currentPoint = startPoint;
}
/*Colour of the line*/
line.Stroke = Colour;
/*Thickness Level*/
line.StrokeThickness = 10;
/*Make it less Jagged and Smoother by changing the Stroke Points*/
line.StrokeDashCap = PenLineCap.Round;
line.StrokeStartLineCap = PenLineCap.Round;
line.StrokeEndLineCap = PenLineCap.Round;
line.StrokeLineJoin = PenLineJoin.Round;
/*Where to Draw the Line in terms of X and Y Positions*/
line.X1 = currentPoint.X;
line.Y1 = currentPoint.Y;
line.X2 = nextPoint.X;
line.Y2 = nextPoint.Y;
/*Current Point = nextPoint*/
currentPoint = nextPoint;
/*Add The Line*/
inkcanvas.Children.Add(line);
}
我弄清楚了,原来我可以简单地使用颜色空间点来记录右手的位置,然后在一个新的函数中再次调用它来确定线的绘制点。
记录CSP:
ColorSpacePoint CSP = this.coordinateMapper.MapCameraPointToColorSpace(Joints[JointType.HandRight]);
然后是编辑函数:
/*Function to Paint/Draw on the Screen*/
public void Paint(ColorSpacePoint Position, InkCanvas inkcanvas)
{
Line line = new Line(); //New Line
/*If Co-ords are equal to 0,0 reset them*/
if (Position.X == 0 && Position.Y == 0)
{
NextPoint = Position
}
/*Colour of the line*/
line.Stroke = Colour;
/*Thickness Level*/
line.StrokeThickness = 10;
/*Make it less Jagged and Smoother by changing the Stroke Points*/
line.StrokeDashCap = PenLineCap.Round;
line.StrokeStartLineCap = PenLineCap.Round;
line.StrokeEndLineCap = PenLineCap.Round;
line.StrokeLineJoin = PenLineJoin.Round;
/*Where to Draw the Line in terms of X and Y Positions*/
line.X1 = Position.X;
line.Y1 = Position.Y;
line.X2 = Position.X + 0.01;
line.Y2 = Position.Y + 0.01;
/*Add The Line after Scaling*/
Inkcanvas.SetLeft(line , Position.X - line.Width / 2);
Ink canvas.SetTop(line, Position.Y - line.Height / 2);
inkcanvas.Children.Add(line);
}
这将在用户右手所在的地方绘制小线条,但是我决定使用椭圆,而不是绘制许多小线条来形成一条大线条:
public void DrawPoint(ColorSpacePoint point)
{
// Create an ellipse.
Ellipse ellipse = new Ellipse
{
Width = 20,
Height = 20,
Fill = Brushes.Red
};
// Position the ellipse according to the point's coordinates.
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
// Add the ellipse to the canvas.
canvas.Children.Add(ellipse);
}