/// <summary> /// Handles the body frame data arriving from the sensor /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void Reader_FrameArrived(BodyFrameArrivedEventArgs e, SoD_Sensor.MainWindow.SODMessage assocation) { BodyFrameReference frameReference = e.FrameReference; try { BodyFrame frame = frameReference.AcquireFrame(); if (frame != null) { // BodyFrame is IDisposable using (frame) { using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size dc.DrawRectangle(Brushes.Transparent, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array. // As long as those body objects are not disposed and not set to null in the array, // those body objects will be re-used. frame.GetAndRefreshBodyData(this.bodies); foreach (Body body in this.bodies) { if (body.IsTracked) { this.DrawClippedEdges(body, dc); IReadOnlyDictionary<JointType, Joint> joints = body.Joints; // convert the joint points to depth (display) space Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>(); foreach (JointType jointType in joints.Keys) { DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(joints[jointType].Position); jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y); } this.DrawBody(joints, jointPoints, dc); this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc); this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc); //draw uniquePersonID if (SoD_Sensor.MainWindow.socket!=null) { if (assocation.data != null) { // Console.WriteLine("HUH? "+(assocation.data.Property("-1")==null)); try { //Console.WriteLine("HAHA"+assocation.data); if (assocation.data.Property(body.TrackingId.ToString()) != null) { var text = new FormattedText(assocation.data[body.TrackingId.ToString()].ToString(), System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Calibri"), 50, Brushes.DodgerBlue); dc.DrawText(text, new Point(jointPoints[JointType.Head].X - 20, jointPoints[JointType.Head].Y - 80)); } } catch (Exception exception) { Console.WriteLine("YO"+exception); } } else { //Console.WriteLine("Data NULL"); } } }// if the socket is connected } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } } } } catch (Exception) { // ignore if the frame is no longer available } }
public void renderBodyFrame(BodyFrameArrivedEventArgs e,SoD_Sensor.MainWindow.SODMessage assocation) { Reader_FrameArrived(e,assocation); }