2015-07-18 79 views
0

我希望能够正确地映射坐标,以便在InkCanvas移动时我的手在其上生成一条线。Kinect Sdk 2.0地图坐标正确吗?

我目前使用DepthSpacePoint这样的:

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才能看到画布上的线条,我做错了什么?我该如何纠正? 这是我的画图功能:

/*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); 

    } 

回答

0

我想通了,原来我可以简单地只使用颜色空间中的点记录的右手,然后调用它的位置又在一个新的功能,以确定该线的绘制点。

录制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); 
}