2015-07-18 94 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); 
}