コード例 #1
0
        /// <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(object sender, BodyFrameArrivedEventArgs e)
        {
            int  p            = 0;
            bool dataReceived = false;

            this.JsonObject.Persons.Clear();

            using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    if (this.bodies == null)
                    {
                        this.bodies = new Body[bodyFrame.BodyCount];
                    }

                    // 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.
                    bodyFrame.GetAndRefreshBodyData(this.bodies);
                    dataReceived = true;
                }
            }

            if (dataReceived)
            {
                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    // Draw a transparent background to set the render size
                    ImageDrawing img = new ImageDrawing(this.colorBitmap, new Rect(0, 0, this.displayWidth, this.displayHeight));
                    dc.DrawDrawing(img);

                    int penIndex = 0;
                    foreach (Body body in this.bodies)
                    {
                        writer.WriteStartArrayAsync();

                        Pen drawPen = this.bodyColors[penIndex++];

                        if (body.IsTracked)
                        {
                            this.JsonObject.Persons.Add(new person(p++));

                            this.DrawClippedEdges(body, dc); // 1296 x 1080

                            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)
                            {
                                poseData PoseData = new poseData();

                                // sometimes the depth(Z) of an inferred joint may show as negative
                                // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
                                CameraSpacePoint position = joints[jointType].Position;
                                if (position.Z < 0)
                                {
                                    position.Z = InferredZPositionClamp;
                                }

                                ColorSpacePoint colorSpacePoint = this.coordinateMapper.MapCameraPointToColorSpace(position);
                                jointPoints[jointType] = new Point(colorSpacePoint.X, colorSpacePoint.Y);

                                PoseData.index = (int)jointType;
                                PoseData.x     = (int)colorSpacePoint.X;
                                PoseData.y     = (int)colorSpacePoint.Y;
                                PoseData.z     = position.Z;

                                this.JsonObject.Persons[this.JsonObject.Persons.Count - 1].PoseData[PoseData.index] = PoseData;
                            }

                            this.DrawBody(joints, jointPoints, dc, drawPen);

                            this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
                            this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);
                        }
                    }

                    // prevent drawing outside of our render area
                    this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
                    this.drawLaneBorders(dc);
                }
            }

#if DEBUG
            nbConsole.WriteLine(sw.ToString());
#endif
            string jsonString = JsonConvert.SerializeObject(this.JsonObject);
            TCPSocket.sendmsg(jsonString + "\n"); //add LF because it makes server side parsing easier
            sb.Clear();
        }
コード例 #2
0
 public person(int myindex)
 {
     index    = myindex;
     PoseData = new poseData[25];
 }