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