用kinect统计人数,基于微软的skeleton tracking

   private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
               {
                Skeleton[] skeletons = new Skeleton[0];


                using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
               {
                     if (skeletonFrame == null)
                     {
                         textBox1.Text = "0";
                         //return 0;
                     }
                     if (skeletonFrame != null)
                     {
                         skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
                         skeletonFrame.CopySkeletonDataTo(skeletons);
                        


                         //Kinect only get the position
                         int noTrac = (from s in skeletons
                                       where s.TrackingState == SkeletonTrackingState.PositionOnly
                                       select s).Count();


                         //kinect tracked
                         int getTrac = (from s in skeletons
                                        where s.TrackingState == SkeletonTrackingState.Tracked
                                        select s).Count();


                         int numberOfSkeletons = noTrac + getTrac;
                         this.textBox1.Text = numberOfSkeletons.ToString();//output the number in textbox
                     }
                
               }


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

在做一个关于kinect的项目,要检测在kinect前的人数。。。我想用kinect骨骼追踪然后把追踪的数目加起来。 问题是,kinect追踪到一个骨骼后是持续追踪这个骨骼的动作,而且最多追踪2个。怎么能在在打开kinect的时候就能得出有多少人?有新的人进来后count会直接增加?小弟是新手。求各位帮帮忙。。。用的是C#
我在kinect skeleton 后面加了个代码
private int GetTotalSkeleton(AllFramesReadyEventArgs e)
       {
 
           using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
           {
               if (skeletonFrameData == null)
               {
                    return 0;
               }
 
 
               skeletonFrameData.CopySkeletonDataTo( allSkeletons);
 
               //Pessoas nao rastreados
               int noTrac = (from s in allSkeletons
                                        where s.TrackingState == SkeletonTrackingState.PositionOnly
                                        select s).Count();
 
               //Pessoas com esqueleto
               int comEsq = (from s in allSkeletons
                             where s.TrackingState == SkeletonTrackingState.Tracked
                             select s).Count();
 
               int numberOfSkeletons = noTrac + comEsq;
 
               return numberOfSkeletons;
 
           }
 
       }
红字说有错误,return那个把void改成int解决了。。。allSkeletons改成totalskeleton可以吗?这个代码可以实现统计人数吗?

你可能感兴趣的:(用kinect统计人数,基于微软的skeleton tracking)