【问题标题】:Kinect SDK 2.0, Mapping skeleton to Image Overlay?Kinect SDK 2.0,将骨架映射到图像叠加层?
【发布时间】:2015-04-20 22:10:44
【问题描述】:

基本上我有一个摄像头流,我试图在摄像头流上覆盖一个骨架,我可以成功地做到这一点,骨架没有正确映射到流的顶部。

我尝试使用坐标映射器并将深度空间点更改为 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>``

如果您有更多信息,请提前致谢

【问题讨论】:

  • 您的 XAML 是什么样的?部分问题可能是视觉元素没有排列
  • 给我 5 分钟,我将编辑帖子,并为您输入我的 Xaml 编码。
  • Xaml 已发布,我多次查看我看不到我做错了什么

标签: c# xaml visual-studio-2013 kinect


【解决方案1】:

好的,我看到您为相机和骨架使用了单独的Image;我使用DrawingGroup 让骨架和相机对齐。另外,我通常不依赖Grids 来放置我的Images - 我将所有内容都放在Canvas 上,或者如果您真的需要Grid,请将Images 放在同一个单元格中Grid

请查看this question 以获取使用DrawingGroup 的示例。

【讨论】:

  • 如何将两个图像放在网格的同一个单元格上?
猜你喜欢
  • 2013-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-04
  • 1970-01-01
相关资源
最近更新 更多