void uTracker_onNewData(UserTracker uTracker) { if (!uTracker.isValid) return; using (UserTrackerFrameRef frame = uTracker.readFrame()) { if (!frame.isValid) return; lock (image) { if (image.Width != frame.UserMap.FrameSize.Width || image.Height != frame.UserMap.FrameSize.Height) image = new Bitmap(frame.UserMap.FrameSize.Width, frame.UserMap.FrameSize.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); using (Graphics g = Graphics.FromImage(image)) { g.FillRectangle(Brushes.Black, new Rectangle(new Point(0, 0), image.Size)); foreach (UserData user in frame.Users) { if (user.isNew && user.isVisible) uTracker.StartSkeletonTracking(user.UserId); if (user.isVisible && user.Skeleton.State == Skeleton.SkeletonState.TRACKED) { DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.RIGHT_HAND, SkeletonJoint.JointType.RIGHT_ELBOW); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.LEFT_HAND, SkeletonJoint.JointType.LEFT_ELBOW); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.RIGHT_ELBOW, SkeletonJoint.JointType.RIGHT_SHOULDER); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.LEFT_ELBOW, SkeletonJoint.JointType.LEFT_SHOULDER); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.RIGHT_FOOT, SkeletonJoint.JointType.RIGHT_KNEE); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.LEFT_FOOT, SkeletonJoint.JointType.LEFT_KNEE); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.RIGHT_KNEE, SkeletonJoint.JointType.RIGHT_HIP); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.LEFT_KNEE, SkeletonJoint.JointType.LEFT_HIP); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.RIGHT_SHOULDER, SkeletonJoint.JointType.LEFT_SHOULDER); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.RIGHT_HIP, SkeletonJoint.JointType.LEFT_HIP); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.RIGHT_SHOULDER, SkeletonJoint.JointType.RIGHT_HIP); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.LEFT_SHOULDER, SkeletonJoint.JointType.LEFT_HIP); DrawLineBetweenJoints(g, user.Skeleton, SkeletonJoint.JointType.HEAD, SkeletonJoint.JointType.NECK); } } g.Save(); } } this.Invoke(new MethodInvoker(delegate() { fps = ((1000000 / (frame.Timestamp - lastTime)) + (fps * 4)) / 5; lastTime = frame.Timestamp; this.Text = "Frame #" + frame.FrameIndex.ToString() + " - Time: " + frame.Timestamp.ToString() + " - FPS: " + fps.ToString(); pb_preview.Image = image.Clone(new Rectangle(new Point(0, 0), image.Size), System.Drawing.Imaging.PixelFormat.Format24bppRgb); })); } }
void uTracker_onNewData(UserTracker uTracker) { if (!uTracker.isValid) return; using (UserTrackerFrameRef frame = uTracker.readFrame()) { if (!frame.isValid) return; UserMap um = frame.UserMap; FillImageFromUserMap(frame.UserMap); UserData[] ud = frame.Users; using (Graphics g = Graphics.FromImage(image)) { foreach (UserData user in frame.Users) { if (user.CenterOfMass.Z > 0) { Point p = new Point(); PointF pf = uTracker.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() { fps = ((1000000 / (frame.Timestamp - lastTime)) + (fps * 4)) / 5; lastTime = frame.Timestamp; this.Text = "Frame #" + frame.FrameIndex.ToString() + " - Time: " + frame.Timestamp.ToString() + " - FPS: " + fps.ToString(); pb_preview.Image = image.Clone(new Rectangle(new Point(0,0), image.Size), System.Drawing.Imaging.PixelFormat.Format24bppRgb); })); } }