Exemplo n.º 1
0
 private void NiTeOnNewData(HandTracker handTracker)
 {
     try
     {
         if (Settings.Default.SmartCam && this.uTracker != null && this.uTracker.IsValid && this.hTracker != null &&
             this.hTracker.IsValid)
         {
             using (UserTrackerFrameRef userframe = this.uTracker.ReadFrame())
             {
                 using (HandTrackerFrameRef handframe = this.hTracker.ReadFrame())
                 {
                     foreach (GestureData gesture in handframe.Gestures)
                     {
                         if (!gesture.IsComplete)
                         {
                             continue;
                         }
                         PointF handPos = this.hTracker.ConvertHandCoordinatesToDepth(gesture.CurrentPosition);
                         short  userId  =
                             Marshal.ReadByte(
                                 userframe.UserMap.Pixels + (int)(handPos.Y * userframe.UserMap.DataStrideBytes)
                                 + (int)(handPos.X * 2));
                         if (userId > 0)
                         {
                             this.activeUserId = userId;
                         }
                     }
                     handframe.Release();
                 }
                 if (this.activeUserId > 0)
                 {
                     UserData user = userframe.GetUserById(this.activeUserId);
                     if (user.IsValid && user.IsVisible && user.CenterOfMass.Z > 0)
                     {
                         RectangleF position    = new RectangleF(0, 0, 0, 0);
                         PointF     botlocation = this.uTracker.ConvertJointCoordinatesToDepth(user.CenterOfMass);
                         int        pSize       =
                             (int)
                             (Math.Max((int)((4700 - user.CenterOfMass.Z) * 0.08), 50)
                              * ((float)userframe.UserMap.FrameSize.Height / 480));
                         position.Y                 = (int)botlocation.Y - pSize;
                         position.Height            = pSize;
                         position.X                 = (int)botlocation.X;
                         this.activePosition.X      = position.X / userframe.UserMap.FrameSize.Width;
                         this.activePosition.Width  = position.Width / userframe.UserMap.FrameSize.Width;
                         this.activePosition.Y      = position.Y / userframe.UserMap.FrameSize.Height;
                         this.activePosition.Height = position.Height / userframe.UserMap.FrameSize.Height;
                         userframe.Release();
                         return;
                     }
                 }
                 userframe.Release();
             }
         }
     }
     catch (Exception)
     {
     }
     this.activeUserId = 0;
 }
Exemplo n.º 2
0
        // ReSharper disable once ParameterHidesMember
        private void UserTrackerOnNewData(UserTracker userTracker)
        {
            if (!userTracker.IsValid)
            {
                return;
            }

            UserTrackerFrameRef frame = userTracker.ReadFrame();

            if (frame == null || !frame.IsValid)
            {
                return;
            }

            this.FillImageFromUserMap(frame.UserMap);

            using (Graphics g = Graphics.FromImage(this.image))
            {
                foreach (UserData user in frame.Users)
                {
                    if (user.CenterOfMass.Z > 0)
                    {
                        Point  p  = new Point();
                        PointF pf = userTracker.ConvertJointCoordinatesToDepth(user.CenterOfMass);
                        p.X = (int)pf.X - 5;
                        p.Y = (int)pf.Y - 5;
                        g.DrawEllipse(new Pen(Brushes.White, 5), new Rectangle(p, new Size(5, 5)));
                        g.DrawString("Center Of Mass", SystemFonts.DefaultFont, Brushes.White, p.X - 40, p.Y - 20);
                    }
                }

                g.Save();
            }

            this.Invoke(
                new MethodInvoker(
                    delegate
            {
                this.fps      = ((1000000 / (frame.Timestamp - this.lastTime)) + (this.fps * 4)) / 5;
                this.lastTime = frame.Timestamp;
                this.Text     = string.Format(
                    "Frame #{0} - Time: {1} - FPS: {2}",
                    frame.FrameIndex,
                    frame.Timestamp,
                    this.fps);
                this.pb_preview.Image = this.image.Clone(
                    new Rectangle(new Point(0, 0), this.image.Size),
                    PixelFormat.Format24bppRgb);
                frame.Release();
            }));
        }
Exemplo n.º 3
0
        // ReSharper disable once ParameterHidesMember
        private void UserTrackerOnNewData(UserTracker userTracker)
        {
            if (!userTracker.IsValid)
            {
                return;
            }

            UserTrackerFrameRef frame = userTracker.ReadFrame();

            if (frame == null || !frame.IsValid)
            {
                return;
            }

            lock (this.image)
            {
                if (this.image.Width != frame.UserMap.FrameSize.Width ||
                    this.image.Height != frame.UserMap.FrameSize.Height)
                {
                    this.image = new Bitmap(
                        frame.UserMap.FrameSize.Width,
                        frame.UserMap.FrameSize.Height,
                        PixelFormat.Format24bppRgb);
                }

                using (Graphics g = Graphics.FromImage(this.image))
                {
                    g.FillRectangle(Brushes.Black, new Rectangle(new Point(0, 0), this.image.Size));
                    foreach (UserData user in frame.Users)
                    {
                        if (user.IsNew && user.IsVisible)
                        {
                            userTracker.StartSkeletonTracking(user.UserId);
                        }

                        if (user.IsVisible && user.Skeleton.State == Skeleton.SkeletonState.Tracked)
                        {
                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.RightHand,
                                SkeletonJoint.JointType.RightElbow);
                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.LeftHand,
                                SkeletonJoint.JointType.LeftElbow);

                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.RightElbow,
                                SkeletonJoint.JointType.RightShoulder);
                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.LeftElbow,
                                SkeletonJoint.JointType.LeftShoulder);

                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.RightFoot,
                                SkeletonJoint.JointType.RightKnee);
                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.LeftFoot,
                                SkeletonJoint.JointType.LeftKnee);

                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.RightKnee,
                                SkeletonJoint.JointType.RightHip);
                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.LeftKnee,
                                SkeletonJoint.JointType.LeftHip);

                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.RightShoulder,
                                SkeletonJoint.JointType.LeftShoulder);
                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.RightHip,
                                SkeletonJoint.JointType.LeftHip);

                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.RightShoulder,
                                SkeletonJoint.JointType.RightHip);
                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.LeftShoulder,
                                SkeletonJoint.JointType.LeftHip);

                            this.DrawLineBetweenJoints(
                                g,
                                user.Skeleton,
                                SkeletonJoint.JointType.Head,
                                SkeletonJoint.JointType.Neck);
                        }
                    }

                    g.Save();
                }
            }

            this.Invoke(
                new MethodInvoker(
                    delegate
            {
                this.fps      = ((1000000 / (frame.Timestamp - this.lastTime)) + (this.fps * 4)) / 5;
                this.lastTime = frame.Timestamp;
                this.Text     = string.Format(
                    "Frame #{0} - Time: {1} - FPS: {2}",
                    frame.FrameIndex,
                    frame.Timestamp,
                    this.fps);
                this.pb_preview.Image = this.image.Clone(
                    new Rectangle(new Point(0, 0), this.image.Size),
                    PixelFormat.Format24bppRgb);
                frame.Release();
            }));
        }