Esempio n. 1
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();
                        }));
        }
Esempio 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();
                        }));
        }
Esempio n. 3
0
        private void SkeletonSensor_OnNewData(UserTracker userTracker)
        {
            if (!userTracker.IsValid)
                return;

            ulong currentTimeTicks = 0;
            Skeleton validSkeleton = null;
            using (UserTrackerFrameRef frame = userTracker.ReadFrame())
            {
                if (frame == null || !frame.IsValid)
                    return;

                foreach (UserData user in frame.Users)
                {
                    if (user.IsNew && user.IsVisible)
                    {
                        userTracker.StartSkeletonTracking(user.UserId);
                    }
                    if (user.IsVisible && user.Skeleton.State == Skeleton.SkeletonState.Tracked)
                    {
                        validSkeleton = user.Skeleton;
                        break;
                    }
                }
                currentTimeTicks = frame.Timestamp;
            }

            if (validSkeleton != null && IsEngineStart)
            {
                double deltaTimeTicks = (currentTimeTicks - lastUpdate);
                if (lastUpdate == 0)
                    deltaTimeTicks = 0;
                lastUpdate = currentTimeTicks;
                RunFatigueEngine(validSkeleton, deltaTimeTicks / 1000000);
            }

            Dispatcher.Invoke((Action)delegate
            {
                iKinectCapture.Source = kinectSensor.RawImageSource;
                if (validSkeleton != null)
                    iSkeleton.Source = DrawSkeleton(validSkeleton, Brushes.Transparent);
                else
                    iSkeleton.Source = null;
            });
        }