2015-04-20 34 views
0

基本上我有一個相機流,我試圖覆蓋在相機流頂部的骨架,我可以成功地做到這一點如何骨架沒有正確地映射在流的頂部。Kinect SDK 2.0,映射骨架到圖像疊加?

我嘗試過使用座標映射器,並將深度空間點改爲ColorSpacePoint,但是這會使骨架完全消失。

 #region Handling the body frame data arriving from the Sensor for Skeleton 
    /// Handles the body frame data arriving from the sensor 
    /// </summary> 
    /// <param name="sender">object sending the event</param> 
    /// <param name="e">event arguments</param> 
    private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) 
    { 
     // Normal Boolean 
     bool dataReceived = false; 

     //Using = Provides a convenient syntax that ensures the correct use of IDisposable objects. 
     using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame()) 
     { 
      //If from is not Null 
      if (bodyFrame != null) 
      { 
       //If body is not null 
       if (this.bodies == null) 
       { 
        //New body in array number of bodies 
        this.bodies = new Body[bodyFrame.BodyCount]; 
       } 

       // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array. 
       // As long as those body objects are not disposed and not set to null in the array, 
       // those body objects will be re-used. 
       bodyFrame.GetAndRefreshBodyData(this.bodies); 
       dataReceived = true; 
      } 
     } 

     //if Data has been recieved 
     if (dataReceived) 
     { 
      //Use Drawing Group 
      using (DrawingContext dc = this.drawingGroup.Open()) 
      { 
       // Draw a transparent background to set the render size 
       dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); 

       //Set the index of the Pen to 0 
       int penIndex = 0; 

       //For each body 
       foreach (Body body in this.bodies) 
       { 
        //This is the colour of the Pen, It goes in array order for each body. 
        Pen drawPen = this.bodyColors[penIndex++]; 

        //If body is tracked 
        if (body.IsTracked) 
        { 
         this.DrawClippedEdges(body, dc); 

         IReadOnlyDictionary<JointType, Joint> joints = body.Joints; 

         // convert the joint points to depth (display) space 
         Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>(); 




         foreach (JointType jointType in joints.Keys) 
         { 


           // sometimes the depth(Z) of an inferred joint may show as negative 
           // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity) 
           CameraSpacePoint SkeletonPosition = joints[jointType].Position; 

           if (SkeletonPosition.Z < 0) 
           { 
            SkeletonPosition.Z = InferredZPositionClamp; 
           } 

           ColorSpacePoint colorSpacePoint = this.coordinateMapper.MapCameraPointToColorSpace(SkeletonPosition); 
           jointPoints[jointType] = new Point(colorSpacePoint.X/3.75, colorSpacePoint.Y/3.75); //Divide Positions by 3.8 to correctly map skeleton to canvas 

         } 



         //Draw the bodies with the Pen Colour selected on amount of bodies available 
         this.DrawBody(joints, jointPoints, dc, drawPen); 

         //Draw the Left Hand, Feeding in the State and type of Joint 
         this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc); 

         //Draw the right Hand, Feeding in the state and type of Joint 
         this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc); 

         this.test(joints, jointPoints, dc, drawPen, ElbowAngle); 
        } 
       } 

       // prevent drawing outside of our render area 
       this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); 
      } 
     } 

正如你可以看到我嘗試使用ColorSpacePoint對關節的顏色流正常,但由於某種原因,這是行不通的映射,可有人善意解釋什麼即時做錯了什麼?

這裏是我的XAML的樣子:

<Window x:Class="MedicalKinectWPF.FreeFormSkeleton" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:k="http://schemas.microsoft.com/kinect/2014" 
     WindowState="Maximized" 
     Loaded="FreeFormSkeletonWindow_Loaded" 
     Closing="FreeFormSkeletonWindow_Closing" 
     Title="MainWindow" Height="1920" Width="1080" Background="#FF381E1E"> 

    <Window.Resources> 
     <SolidColorBrush x:Key="MediumGreyBrush" Color="#ff6e6e6e" /> 
     <SolidColorBrush x:Key="KinectPurpleBrush" Color="#ff52318f" /> 
     <SolidColorBrush x:Key="KinectBlueBrush" Color="#ff00BCF2" /> 
    </Window.Resources> 

    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="120px" /> 
      <RowDefinition Height="2" /> 
      <RowDefinition Height="*" /> 
      <RowDefinition Height="2" /> 
      <RowDefinition Height="100px" /> 
     </Grid.RowDefinitions> 

     <!-- Free Form Skeleton Title Label (HEADER)--> 
     <Label x:Name="Title" Content = "Free Form Skeleton Demonstration" TextElement.Foreground="Snow" 
        HorizontalAlignment="Center" 
        Margin="318,10,247,0" 
        VerticalAlignment="Top" 
        Height="44" Width="427" 
        FontSize="25" FontWeight="Bold"/> 

      <!-- Seperator --> 
      <Rectangle Grid.Row="1" Grid.ColumnSpan="2" Fill="LightBlue" /> 
      <!-- Kinect Output--> 
      <Grid Grid.Row="2"> 
      <Grid x:Name="CameraSkeletonGrid"> 

       <!-- Camera image --> 
       <Image x:Name="CameraImage" Width="1920" Height="1080" /> 

       <!--Skeleton Image--> 
       <Image Source="{Binding ImageSource}" Stretch="UniformToFill" Width="1920" Height="1080" /> 
      </Grid> 

      <!-- Skeletal Tracking Only --> 
      <Grid x:Name="Skeleton" Margin="20" Visibility="Collapsed"> 
       <Viewbox> 
        <Image Source="{Binding ImageSource}" Stretch="UniformToFill" Width="1920" Height="1080"/> 
       </Viewbox> 
      </Grid> 
     </Grid> 
      <!-- Seperator --> 
     <Rectangle Grid.Row="3" Fill="AliceBlue" /> 
<!-- Navigation --> 
<Grid Grid.Row="4"> 
    <Grid.ColumnDefinitions> 
    <ColumnDefinition /> 
    <ColumnDefinition /> 
    <ColumnDefinition /> 
</Grid.ColumnDefinitions> 
      <!-- Switch to camera & body --> 
      <Button x:Name = "ToggleRGBSkeleton" FontSize="25" FontFamily="Segoe UI Semibold" TextElement.Foreground="Snow" Background="{x:Null}" BorderBrush="White" Click="OnToggleCamera" Cursor="Hand" > 
       <TextBlock Text="RGB Camera With &#xA; Skeleton Overlay"/> 
       </Button> 
      <!-- Switch to Skeleton Only Mode --> 
      <Button x:Name="ToggleSkeleton" Grid.Column="1" FontSize="25"  FontFamily="Segoe UI Semibold" TextElement.Foreground="Snow" Background="{x:Null}" BorderBrush="White" Click="OnToggleSkeleton" Cursor="Hand"> 
       <TextBlock Text="Skeleton Only"/> 
      </Button> 
     </Grid> 
    </Grid> 
</Window>`` 

更多信息,請您,在此先感謝

+0

你的XAML是什麼樣的?部分問題可能是視覺元素不排隊 – redhotspike

+0

給我5分鐘,我將編輯帖子,並將我的Xaml編碼輸入。 – ShatteredPheonix

+0

在此期間此鏈接可能會有所幫助:http://pterneas.com/2014/05/06/understanding-kinect-coordinate-mapping/ – redhotspike

回答

0

好了,我看到你正在使用一個單獨的Image爲您的相機和你骨架;我利用DrawingGroup讓骨架和相機排隊。另外,我通常不會依靠Grid來放置我的Image - 我將所有東西都放在Canvas上,或者如果您確實需要Grid,請將兩個Image放在Grid的同一個單元中。

有關使用DrawingGroup的示例,請參閱this question

+0

如何將兩個圖像放在網格的同一個單元格上? – ShatteredPheonix