本文介绍了sensor.SkeletonStream.ChooseSkeletons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友


我的编程和英语很差。对不起!


i 想要kinect只显示一个人骨架


我的鳕鱼的一部分(来自微软样本):


公共部分类MainWindow:窗口

    {

        ///< summary>

        ///输出图纸的宽度

        ///< / summary>

        private const float RenderWidth = 640.0f;



        ///< summary>

        ///输出图纸的高度

        ///< / summary>

        private const float RenderHeight = 480.0f;



        ///< summary>

        ///绘制的关节线的厚度

        ///< / summary>

        private const double JointThickness = 3;



        ///< summary>

        ///正文中心椭圆的厚度

        ///< / summary>

        private const double BodyCenterThickness = 10;



        ///< summary>

        ///剪辑边缘矩形的厚度

        ///< / summary>

        private const double ClipBoundsThickness = 10;



        ///< summary>

        ///用于绘制骨架中心点的画笔

        ///< / summary>

        private readonly Brush centerPointBrush = Brushes.Blue;



        ///< summary>

        ///用于绘制当前被跟踪的关节的画笔

        ///< / summary>

       私人只读刷trackedJointBrush =新的SolidColorBrush(Color.FromArgb(255,68,192,68));



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; ///< summary>

        ///用于绘制当前推断的关节的画笔

        ///< / summary>        

        private readonly Brush inferredJointBrush = Brushes.Yellow;



        ///< summary>

        ///用于绘制当前被跟踪的骨骼的笔

        ///< / summary>

        private readonly Pen trackedBonePen = new Pen(Brushes.Green,6);



        ///< summary>

        ///用于绘制当前推断骨骼的笔用于
        ///< / summary>        

        private readonly Pen inferredBonePen = new Pen(Brushes.Gray,1);



        ///< summary>

        ///有源Kinect传感器

        ///< / summary>

       私人KinectSensor传感器;



        ///< summary>

        ///骨架渲染输出的绘图组

        ///< / summary>

       私人DrawingGroup drawingGroup;
$


        ///< summary>

        ///我们将展示的图片图像是
        ///< / summary>

        private DrawingImage imageSource;
$


        ///< summary>

        ///初始化MainWindow类的新实例。

        ///< / summary>

        public MainWindow()

        {

            InitializeComponent();

        }


        ///< summary>

        ///绘制指标以显示哪些边是裁剪骨架数据

        ///< / summary>

        ///< param name =" skeleton">骨架,用于绘制< / param>的剪贴信息。

        ///< param name =" drawingContext">绘制上下文以绘制到< / param>

        private static void RenderClippedEdges(Skeleton skeleton,DrawingContext drawingContext)

        {

            if(skeleton.ClippedEdges.HasFlag(FrameEdges.Bottom))

            {

                drawingContext.DrawRectangle(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Brushes.Red,&
                   空,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新矩形(0,RenderHeight - ClipBoundsThickness,RenderWidth,ClipBoundsThickness));

            }


            if(skeleton.ClippedEdges.HasFlag(FrameEdges.Top))

            {

                drawingContext.DrawRectangle(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Brushes.Red,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;空,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新矩形(0,0,RenderWidth,ClipBoundsThickness));

            }


            if(skeleton.ClippedEdges.HasFlag(FrameEdges.Left))

            {

                drawingContext.DrawRectangle(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Brushes.Red,&
                   空,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新矩形(0,0,ClipBoundsThickness,RenderHeight));

            }


           如果(skeleton.ClippedEdges.HasFlag(FrameEdges.Right))

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

                drawingContext.DrawRectangle(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Brushes.Red,&
                   空,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;新矩形(RenderWidth - ClipBoundsThickness,0,ClipBoundsThickness,RenderHeight));

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
        }


        ///< summary>

        ///执行启动任务

        ///< / summary>

        ///< param name =" sender">发送事件的对象< / param>

        ///< param name =" e">事件参数< / param>

        private void WindowLoaded(object sender,RoutedEventArgs e)

        {

          //&NBSP;隐藏();

            //创建我们将用于绘制的绘图组

            this.drawingGroup = new DrawingGroup();
$


            //创建一个我们可以在图像控件中使用的图像源

            this.imageSource = new DrawingImage(this.drawingGroup);
$


            //使用我们的图像控件显示图纸

            Image.Source = this.imageSource;



            //查看所有传感器并启动第一个连接的传感器。

            //这需要在应用启动时连接Kinect。

            //为了使你的应用程序能够防止插拔,


            //它建议使用在Microsoft.Kinect.Toolkit

&NBSP提供KinectSensorChooser;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; foreach(KinectSensor.KinectSensors中的var potentialSensor)

            {

                if(potentialSensor.Status == KinectStatus.Connected)

                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.sensor = potentialSensor;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;休息;

                }
            }


            if(null!= this.sensor)

            {

                //打开骨架流以接收骨架帧

                this.sensor.SkeletonStream.Enable();
$


             &NBSP;&NBSP;&NBSP; //添加要在有新的颜色框数据时调用的事件处理程序

              &NBSP;&NBSP; this.sensor.SkeletonFrameReady + = this.SensorSkeletonFrameReady;



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP; //启动传感器!
$
               试试
                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.sensor.Start();&
                }
                catch(IOException)

                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.sensor = null;&
                }
            }


            if(null == this.sensor)

            {

                this.statusBarText.Text = Properties.Resources.NoKinectReady;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
        }


        ///< summary>

        ///执行关机任务

        ///< / summary>

        ///< param name =" sender">发送事件的对象< / param>

        ///< param name =" e">事件参数< / param>

        private void WindowClosing(object sender,System.ComponentModel.CancelEventArgs e)

        {

            if(null!= this.sensor)

            {

                this.sensor.Stop();

            }
        }
        

        ///< summary>

        /// Kinect传感器的SkeletonFrameReady事件的事件处理程序

        ///< / summary>

        ///< param name =" sender">发送事件的对象< / param>

        ///< param name =" e">事件参数< / param>

        

        private int CurrentTrackingId = 0;



        private void SensorSkeletonFrameReady(object sender,SkeletonFrameReadyEventArgs e)

        {

            Skeleton [] skeletons = new Skeleton [0];

            using(SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())

            {

               

             //&NBSP;&NBSP; Skeleton [] Skeletons = new Skeleton [skeletonFrame.SkeletonArrayLength];


             //&NBSP;&NBSP; int firstSkeleton = Skeletons [0] .TrackingId;


             //&NBSP;&NBSP; sensor.SkeletonStream.ChooseSkeletons(firstSkeleton);

                if(skeletonFrame!= null)

                {

                   

                  //&NBSP; sensor.SkeletonStream.AppChoosesSkeletons = TRUE;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //&NBSP; sensor.SkeletonStream.ChooseSkeletons(骨架[0] .TrackingId);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;骨架=新骨架[skeletonFrame.SkeletonArrayLength];

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; skeletonFrame.CopySkeletonDataTo(骨架);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; // INT firstSkeleton =骨架[0] .TrackingId;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP; &NBSP;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;  

                }
            }
           

            using(DrawingContext dc = this.drawingGroup.Open())

            {

                //绘制透明背景以设置渲染大小

                dc.DrawRectangle(Brushes.Black,空,新的Rect(0.0,0.0,RenderWidth,RenderHeight));



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; if(skeletons.Length!= 0)

                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;的foreach(在骨架骨架的skel)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; RenderClippedEdges(skel中,DC);



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(skel.TrackingState == SkeletonTrackingState.Tracked)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBonesAndJoints(skel中,DC);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;否则,如果(skel.TrackingState == SkeletonTrackingState.PositionOnly)

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; dc.DrawEllipse(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.centerPointBrush,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;空,

&NBSP;&NBSP;&NBSP;&NBSP; ,                    this.SkeletonPointToScreen( skel.Position),

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; BodyCenterThickness,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;                BodyCenterThickness);


&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
                }


                //阻止在我们的渲染区域外绘制

                this.drawingGroup.ClipGeometry =新RectangleGeometry(新的Rect(0.0,0.0,RenderWidth,RenderHeight));

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP; }
        }


        ///< summary>

        ///绘制骨架的骨骼和关节

        ///< / summary>

        ///< param name =" skeleton"> skeleton to draw< / param>

        ///< param name =" drawingContext">绘制上下文以绘制到< / param>

        private void DrawBonesAndJoints(Skeleton skeleton,DrawingContext drawingContext)

        {

            //渲染躯干

            this.DrawBone(骨架,的DrawingContext,JointType.Head,JointType.ShoulderCenter);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(skeleton,drawingContext,JointType.ShoulderCenter,JointType.ShoulderLeft);

            this.DrawBone(skeleton,drawingContext,JointType.ShoulderCenter,JointType.ShoulderRight);

            this.DrawBone(骨架,的DrawingContext,JointType.ShoulderCenter,JointType.Spine);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(骨架,的DrawingContext,JointType.Spine,JointType.HipCenter);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(skeleton,drawingContext,JointType.HipCenter,JointType.HipLeft);

            this.DrawBone(skeleton,drawingContext,JointType.HipCenter,JointType.HipRight);
$


          ;&NBSP;&NBSP; //左臂

            this.DrawBone(骨架,的DrawingContext,JointType.ShoulderLeft,JointType.ElbowLeft);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(骨架,的DrawingContext,JointType.ElbowLeft,JointType.WristLeft);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(skeleton,drawingContext,JointType.WristLeft,JointType.HandLeft);
$


          ;&NBSP;&NBSP; //右臂

            this.DrawBone(骨架,的DrawingContext,JointType.ShoulderRight,JointType.ElbowRight);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(skeleton,drawingContext,JointType.ElbowRight,JointType.WristRight);

            this.DrawBone(骨架,的DrawingContext,JointType.WristRight,JointType.HandRight);



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; //左腿

            this.DrawBone(骨架,的DrawingContext,JointType.HipLeft,JointType.KneeLeft);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(骨架,的DrawingContext,JointType.KneeLeft,JointType.AnkleLeft);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(骨架,的DrawingContext,JointType.AnkleLeft,JointType.FootLeft);



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP; //右腿

            this.DrawBone(skeleton,drawingContext,JointType.HipRight,JointType.KneeRight);

            this.DrawBone(骨架,的DrawingContext,JointType.KneeRight,JointType.AnkleRight);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; this.DrawBone(skeleton,drawingContext,JointType.AnkleRight,JointType.FootRight);

 

         ;&NBSP;&NBSP;&NBSP; //渲染关节

            foreach(在skeleton.Joints中联合关节)
$
            {

               刷drawBrush = NULL;



&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; if(joint.TrackingState == JointTrackingState.Tracked)

                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; drawBrush = this.trackedJointBrush;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
 

                }
                else if(joint.TrackingState == JointTrackingState.Inferred)

                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; drawBrush = this.inferredJointBrush;                  
 

                }


                if(drawBrush!= null)

                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; drawingContext.DrawEllipse(drawBrush,null,this.SkeletonPointToScreen(joint.Position),JointThickness,JointThickness);

           &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; }
            }


        }


        ///< summary>

        ///将SkeletonPoint映射到我们的渲染空间并转换为Point

        ///< / summary>

        ///< param name =" skelpoint">指向地图< / param>

        ///<返回>映射点< / returns>

       私人Point SkeletonPointToScreen(SkeletonPoint skelpoint)

        {

            //将点转换为深度空间。  

            //我们没有直接使用深度,但我们确实需要640x480输出分辨率的分数。

            ; DepthImagePoint depthPoint = this.sensor.MapSkeletonPointToDepth(

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
skelpoint,

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&N BSP;&NBSP;&NBSP;
DepthImageFormat.Resolution640x480Fps30);

           返回新点(depthPoint.X,depthPoint.Y);

        }
///////////////////////////////////////// ////////////////////////////////////////////////// //////////


请编辑代码以解决我的问题


谢谢





解决方案

hi dier friends

my programing and english are poor. sorry!

i  want kinect show just one person skeleton

a part of my cod (from microsoft samples):

public partial class MainWindow : Window
    {
        /// <summary>
        /// Width of output drawing
        /// </summary>
        private const float RenderWidth = 640.0f;

        /// <summary>
        /// Height of our output drawing
        /// </summary>
        private const float RenderHeight = 480.0f;

        /// <summary>
        /// Thickness of drawn joint lines
        /// </summary>
        private const double JointThickness = 3;

        /// <summary>
        /// Thickness of body center ellipse
        /// </summary>
        private const double BodyCenterThickness = 10;

        /// <summary>
        /// Thickness of clip edge rectangles
        /// </summary>
        private const double ClipBoundsThickness = 10;

        /// <summary>
        /// Brush used to draw skeleton center point
        /// </summary>
        private readonly Brush centerPointBrush = Brushes.Blue;

        /// <summary>
        /// Brush used for drawing joints that are currently tracked
        /// </summary>
        private readonly Brush trackedJointBrush = new SolidColorBrush(Color.FromArgb(255, 68, 192, 68));

        /// <summary>
        /// Brush used for drawing joints that are currently inferred
        /// </summary>        
        private readonly Brush inferredJointBrush = Brushes.Yellow;

        /// <summary>
        /// Pen used for drawing bones that are currently tracked
        /// </summary>
        private readonly Pen trackedBonePen = new Pen(Brushes.Green, 6);

        /// <summary>
        /// Pen used for drawing bones that are currently inferred
        /// </summary>        
        private readonly Pen inferredBonePen = new Pen(Brushes.Gray, 1);

        /// <summary>
        /// Active Kinect sensor
        /// </summary>
        private KinectSensor sensor;

        /// <summary>
        /// Drawing group for skeleton rendering output
        /// </summary>
        private DrawingGroup drawingGroup;

        /// <summary>
        /// Drawing image that we will display
        /// </summary>
        private DrawingImage imageSource;

        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Draws indicators to show which edges are clipping skeleton data
        /// </summary>
        /// <param name="skeleton">skeleton to draw clipping information for</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        private static void RenderClippedEdges(Skeleton skeleton, DrawingContext drawingContext)
        {
            if (skeleton.ClippedEdges.HasFlag(FrameEdges.Bottom))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, RenderHeight - ClipBoundsThickness, RenderWidth, ClipBoundsThickness));
            }

            if (skeleton.ClippedEdges.HasFlag(FrameEdges.Top))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, RenderWidth, ClipBoundsThickness));
            }

            if (skeleton.ClippedEdges.HasFlag(FrameEdges.Left))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, ClipBoundsThickness, RenderHeight));
            }

            if (skeleton.ClippedEdges.HasFlag(FrameEdges.Right))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(RenderWidth - ClipBoundsThickness, 0, ClipBoundsThickness, RenderHeight));
            }
        }

        /// <summary>
        /// Execute startup tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
          //  Hide();
            // Create the drawing group we'll use for drawing
            this.drawingGroup = new DrawingGroup();

            // Create an image source that we can use in our image control
            this.imageSource = new DrawingImage(this.drawingGroup);

            // Display the drawing using our image control
            Image.Source = this.imageSource;

            // Look through all sensors and start the first connected one.
            // This requires that a Kinect is connected at the time of app startup.
            // To make your app robust against plug/unplug,
            // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit
            foreach (var potentialSensor in KinectSensor.KinectSensors)
            {
                if (potentialSensor.Status == KinectStatus.Connected)
                {
                    this.sensor = potentialSensor;
                    break;
                }
            }

            if (null != this.sensor)
            {
                // Turn on the skeleton stream to receive skeleton frames
                this.sensor.SkeletonStream.Enable();

                // Add an event handler to be called whenever there is new color frame data
                this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady;

                // Start the sensor!
                try
                {
                    this.sensor.Start();
                }
                catch (IOException)
                {
                    this.sensor = null;
                }
            }

            if (null == this.sensor)
            {
                this.statusBarText.Text = Properties.Resources.NoKinectReady;
            }
        }

        /// <summary>
        /// Execute shutdown tasks
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (null != this.sensor)
            {
                this.sensor.Stop();
            }
        }
        
        /// <summary>
        /// Event handler for Kinect sensor's SkeletonFrameReady event
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        
        private int CurrentTrackingId = 0;

        private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            Skeleton[] skeletons = new Skeleton[0];
            using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
            {
               
             //   Skeleton[] Skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
             //   int firstSkeleton = Skeletons[0].TrackingId;
             //   sensor.SkeletonStream.ChooseSkeletons(firstSkeleton);
                if (skeletonFrame != null)
                {
                   
                  //  sensor.SkeletonStream.AppChoosesSkeletons = true;
                  //  sensor.SkeletonStream.ChooseSkeletons(skeletons[0].TrackingId);
                    skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                    skeletonFrame.CopySkeletonDataTo(skeletons);
                   // int firstSkeleton = skeletons[0].TrackingId;
                    
                    
                }
            }
           
            using (DrawingContext dc = this.drawingGroup.Open())
            {
                // Draw a transparent background to set the render size
                dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight));

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        RenderClippedEdges(skel, dc);

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.DrawBonesAndJoints(skel, dc);
                        }
                        else if (skel.TrackingState == SkeletonTrackingState.PositionOnly)
                        {
                            dc.DrawEllipse(
                            this.centerPointBrush,
                            null,
                            this.SkeletonPointToScreen(skel.Position),
                            BodyCenterThickness,
                            BodyCenterThickness);
                        }
                    }
                }

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

        /// <summary>
        /// Draws a skeleton's bones and joints
        /// </summary>
        /// <param name="skeleton">skeleton to draw</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            // Render Torso
            this.DrawBone(skeleton, drawingContext, JointType.Head, JointType.ShoulderCenter);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight);
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderCenter, JointType.Spine);
            this.DrawBone(skeleton, drawingContext, JointType.Spine, JointType.HipCenter);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipLeft);
            this.DrawBone(skeleton, drawingContext, JointType.HipCenter, JointType.HipRight);

            // Left Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderLeft, JointType.ElbowLeft);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowLeft, JointType.WristLeft);
            this.DrawBone(skeleton, drawingContext, JointType.WristLeft, JointType.HandLeft);

            // Right Arm
            this.DrawBone(skeleton, drawingContext, JointType.ShoulderRight, JointType.ElbowRight);
            this.DrawBone(skeleton, drawingContext, JointType.ElbowRight, JointType.WristRight);
            this.DrawBone(skeleton, drawingContext, JointType.WristRight, JointType.HandRight);

            // Left Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipLeft, JointType.KneeLeft);
            this.DrawBone(skeleton, drawingContext, JointType.KneeLeft, JointType.AnkleLeft);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleLeft, JointType.FootLeft);

            // Right Leg
            this.DrawBone(skeleton, drawingContext, JointType.HipRight, JointType.KneeRight);
            this.DrawBone(skeleton, drawingContext, JointType.KneeRight, JointType.AnkleRight);
            this.DrawBone(skeleton, drawingContext, JointType.AnkleRight, JointType.FootRight);
 
            // Render Joints
            foreach (Joint joint in skeleton.Joints)
            {
                Brush drawBrush = null;

                if (joint.TrackingState == JointTrackingState.Tracked)
                {
                    drawBrush = this.trackedJointBrush;                    
                }
                else if (joint.TrackingState == JointTrackingState.Inferred)
                {
                    drawBrush = this.inferredJointBrush;                    
                }

                if (drawBrush != null)
                {
                    drawingContext.DrawEllipse(drawBrush, null, this.SkeletonPointToScreen(joint.Position), JointThickness, JointThickness);
                }
            }

        }

        /// <summary>
        /// Maps a SkeletonPoint to lie within our render space and converts to Point
        /// </summary>
        /// <param name="skelpoint">point to map</param>
        /// <returns>mapped point</returns>
        private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
        {
            // Convert point to depth space.  
            // We are not using depth directly, but we do want the points in our 640x480 output resolution.
            DepthImagePoint depthPoint = this.sensor.MapSkeletonPointToDepth(
                                                                             skelpoint,
                                                                             DepthImageFormat.Resolution640x480Fps30);
            return new Point(depthPoint.X, depthPoint.Y);
        }
/////////////////////////////////////////////////////////////////////////////////////////////////////

please edit code to solve my problem

thanks

解决方案


这篇关于sensor.SkeletonStream.ChooseSkeletons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:34