Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomBody"/> class.
        /// </summary>
        public CustomBody()
        {
            _clippedEdges = FrameEdges.None;

            _handLeftConfidence = TrackingConfidence.Low;
            _handLeftState = HandState.Unknown;
            _handRightConfidence = TrackingConfidence.Low;
            _handRightState = HandState.Unknown;
            _isDisposed = false;
            _isRestricted = false;
            _isTracked = false;

            _joints = new Dictionary<JointType, IJoint>();
            _jointOrientations = new Dictionary<JointType, IJointOrientation>();
            foreach (var jointType in CustomJointType.AllJoints)
            {
                _joints.Add(jointType, new CustomJoint(jointType));
                _jointOrientations.Add(jointType, new CustomJointOrientation(jointType));
            }

            _lean = new PointF();

            _leanTrackingState = TrackingState.NotTracked;
            _trackingId = ulong.MaxValue;
            _hasMappedDepthPositions = false;
            _hasMappedColorPositions = false;
        }
Example #2
0
        /// <summary>
        /// Constructs a body adapter from a serialized version
        /// </summary>
        /// <param name="body"></param>
        public KinectBody(KGP.Serialization.Body.KinectBodyInternal body)
        {
            body.Validate(); //This will check preconditions to make sure we have a valid construct

            this.clippedEdges = body.ClippedEdges;
            this.handLeftConfidence = body.HandLeftConfidence;
            this.handLeftState = body.HandLeftState;
            this.handRightConfidence = body.HandRightConfidence;
            this.handRightState = body.HandRightState;
            this.isRestricted = body.IsRestricted;
            this.isTracked = body.IsTracked;

            Dictionary<JointType, JointOrientation> orientations = new Dictionary<JointType, JointOrientation>();
            Dictionary<JointType, Joint> jointsDic = new Dictionary<JointType,Joint>();
            for (int i = 0; i < body.Joints.Length;i++)
            {
                var joint = body.Joints[i];
                orientations.Add(joint.JointType, body.JointOrientations[i]);
                jointsDic.Add(joint.JointType, joint);

            }

            this.joints = jointsDic;
            this.jointOrientations =orientations;

            this.lean = body.Lean;
            this.leanTrackingState = body.LeanTrackingState;
            this.trackingId = body.TrackingId;
        }
Example #3
0
 private void DrawLeft(FrameEdges clippedEdges)
 {
     if (clippedEdges.HasFlag(FrameEdges.Left))
     {
         var rect = new Rect(0, 0, ClipBoundsThickness, this.displaySize.Height);
         drawingContext.DrawRectangle(Brushes.Red, null, rect);
     }
 }
Example #4
0
 private void DrawBottom(FrameEdges clippedEdges)
 {
     if (clippedEdges.HasFlag(FrameEdges.Bottom))
     {
         var rect = new Rect(0, this.displaySize.Height - ClipBoundsThickness, this.displaySize.Width, ClipBoundsThickness);
         drawingContext.DrawRectangle(Brushes.Red, null, rect);
     }
 }
Example #5
0
 /// <summary>
 /// Constructs a body adapter from a kinect sdk body
 /// </summary>
 /// <param name="body">Body from Kinect SDK</param>
 public KinectBody(Microsoft.Kinect.Body body)
 {
     this.clippedEdges = body.ClippedEdges;
     this.handLeftConfidence = body.HandLeftConfidence;
     this.handLeftState = body.HandLeftState;
     this.handRightConfidence = body.HandRightConfidence;
     this.handRightState = body.HandRightState;
     this.isRestricted = body.IsRestricted;
     this.isTracked = body.IsTracked;
     this.jointOrientations = body.JointOrientations;
     this.joints = body.Joints;
     this.lean = body.Lean;
     this.leanTrackingState = body.LeanTrackingState;
     this.trackingId = body.TrackingId;
 }
Example #6
0
        /// <summary>
        /// Draws indicators to show which edges are clipping body data
        /// </summary>
        /// <param name="body">body to draw clipping information for</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        private void DrawClippedEdges(Body body, DrawingContext drawingContext)
        {
            FrameEdges clippedEdges = body.ClippedEdges;

            if (clippedEdges.HasFlag(FrameEdges.Bottom))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, this.displayHeight - ClipBoundsThickness, this.displayWidth, ClipBoundsThickness));
            }

            if (clippedEdges.HasFlag(FrameEdges.Top))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, this.displayWidth, ClipBoundsThickness));
            }

            if (clippedEdges.HasFlag(FrameEdges.Left))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, ClipBoundsThickness, this.displayHeight));
            }

            if (clippedEdges.HasFlag(FrameEdges.Right))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(this.displayWidth - ClipBoundsThickness, 0, ClipBoundsThickness, this.displayHeight));
            }
        }
Example #7
0
        private void DrawClippedEdges(TSkeleton body, DrawingContext drawingContext)
        {
            FrameEdges clippedEdges = body.ClippedEdges;

            if (clippedEdges.HasFlag(FrameEdges.Bottom))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, HendlerHolder.DisplayHeight - HendlerHolder.ClipBoundsThickness, HendlerHolder.DisplayWidth, HendlerHolder.ClipBoundsThickness));
            }

            if (clippedEdges.HasFlag(FrameEdges.Top))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, HendlerHolder.DisplayWidth, HendlerHolder.ClipBoundsThickness));
            }

            if (clippedEdges.HasFlag(FrameEdges.Left))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(0, 0, HendlerHolder.ClipBoundsThickness, HendlerHolder.DisplayHeight));
            }

            if (clippedEdges.HasFlag(FrameEdges.Right))
            {
                drawingContext.DrawRectangle(
                    Brushes.Red,
                    null,
                    new Rect(HendlerHolder.DisplayWidth - HendlerHolder.ClipBoundsThickness, 0, HendlerHolder.ClipBoundsThickness, HendlerHolder.DisplayHeight));
            }
        }
Example #8
0
        /// <summary>
        /// Draws indicators to show which edges are clipping body data
        /// </summary>
        /// <param name="body">body to draw clipping information for</param>
        /// <param name="drawingContext">drawing context to draw to</param>
        public void DrawClippedEdges(Body body)
        {
            FrameEdges clippedEdges = body.ClippedEdges;

            if (clippedEdges.HasFlag(FrameEdges.Bottom))
            {
                this.imageSource.DrawRectangle(0, this.displayHeight - ClipBoundsThickness, this.displayWidth, ClipBoundsThickness, Color.FromRgb(255, 0, 0));
            }

            if (clippedEdges.HasFlag(FrameEdges.Top))
            {
                this.imageSource.DrawRectangle(0, 0, this.displayWidth, ClipBoundsThickness, Color.FromRgb(255, 0, 0));
            }

            if (clippedEdges.HasFlag(FrameEdges.Left))
            {
                this.imageSource.DrawRectangle(0, 0, ClipBoundsThickness, this.displayHeight, Color.FromRgb(255, 0, 0));
            }

            if (clippedEdges.HasFlag(FrameEdges.Right))
            {
                this.imageSource.DrawRectangle(this.displayWidth - ClipBoundsThickness, 0, ClipBoundsThickness, this.displayHeight, Color.FromRgb(255, 0, 0));
            }
        }
Example #9
0
        private void detectFall(Body body, Plane theFloor, FrameEdges clippedEdges)
        {
            //condifdence proportional to head off ground
            //factor1 distance of head off ground
            if (this.hitEdge == true) { return; }
            
            var distanceToGround = this.headOffFloor(body.Joints[JointType.Head].Position, this.theFloor);

            float fallVelocity = 0;

            if (theCount % 1 == 0) //changing intervals of velocity detection
            {
                watch.Stop();

                headPoints.Add(body.Joints[JointType.Head].Position); //needs clean up
                if (headPoints.Count > 2)
                {
                    fallVelocity = (float)(2 * ((headPoints[headPoints.Count - 1].Y) - (headPoints[headPoints.Count - 2].Y)) / (watch.ElapsedMilliseconds * .001));
                    //will implement velocity and confidence as an additional factor
                }


                watch.Reset();
                watch.Start();
            }
            //  Console.WriteLine(fallVelocity);

            //  Console.WriteLine(distanceToGround); 

            if (distanceToGround <= .5f) //60cm threshold for detection
            {
                if (fallDetected != true)
                {
                    this.fallDetected = true;
                    incapacitatedStopWatch.Reset();
                    incapacitatedStopWatch.Start();

                    
                        String question = "I have detected a fall. " + App.UserName + "Are you alright?";
                        synth.SpeakAsync(question);
                 
                        fallDetectedLoopCount++;



                }
            }

            if (this.scanningHealthMode == true && distanceToGround > 1f)
            {
                Console.WriteLine("Stood up");
               

               // scanningHealthMode = false;
                this.returnToIdle();
            }
            if (this.userIncapacitated == true && distanceToGround > 1f)
            {
                Console.WriteLine("Stood up");
                this.returnToIdle();
            }
            {

            }

        }
Example #10
0
        private void showBodyFrame(BodyFrame bodyFrame, bool dataReceived)
        {
            if (fallDetected)
            {
                elapsedFallTime = this.incapacitatedStopWatch.ElapsedMilliseconds * .001;
                if (elapsedFallTime >= 8 && responseToFallCount ==0)
                {
                    incapacitatedStopWatch.Stop();
                    synth.SpeakAsync("No response detected");
                    this.incapacitationDetected();
                }
                
            }
            if (bodyFrame != null)
            {
                this.theFloor = new Plane(bodyFrame.FloorClipPlane); //get floor plane

                if (this.bodies == null)
                {
                    this.bodies = new Body[bodyFrame.BodyCount];
                }

                bodyFrame.GetAndRefreshBodyData(this.bodies);
                dataReceived = true;
            }


            if (dataReceived)
            {
                using (DrawingContext dc = this.drawingGroup.Open())
                {
                    dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));

                    int penIndex = 0;
                    foreach (Body body in this.bodies)
                    {
                        Pen drawPen = this.bodyColors[penIndex++];
                        FrameEdges clippedEdges = body.ClippedEdges;

                            if (body.IsTracked)
                            {


                                this.DrawClippedEdges(body, dc);
                                IReadOnlyDictionary<JointType, Joint> joints = body.Joints;



                                detectFall(body, theFloor,clippedEdges);



                                Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>();


                                foreach (JointType jointType in joints.Keys)
                                {

                                    CameraSpacePoint position = joints[jointType].Position;
                                    if (position.Z < 0)
                                    {
                                        position.Z = InferredZPositionClamp;
                                    }

                                    DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position);


                                    jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
                                }


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

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

                    this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight));
                }
            }
        }
 public Kinect2KitBody(string trackingId, FrameEdges clippedEdges)
 {
     this.TrackingId   = trackingId;
     this.ClippedEdges = clippedEdges;
 }
        void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var reference = e.FrameReference.AcquireFrame();

            // Color
            using (var frame = reference.ColorFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (viewer.Visualization == Visualization.Color)
                    {
                        viewer.Image = frame.ToBitmap();
                    }
                }
            }

            // Body
            using (var frame = reference.BodyFrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    var bodies = frame.Bodies();

                    _userReporter.Update(bodies);

                    Body body = bodies.Closest();



                    if (body != null)
                    {
                        FrameEdges clippedEdges = body.ClippedEdges;

                        viewer.DrawBody(body, 15, Brushes.Red, 8, Brushes.Aqua);

                        _recorder.Update(body);
                        DateTime currentT = DateTime.Now;
                        TimeSpan elapsed  = currentT - startTime;

                        //Stop recording if duration is not default (0) and reached duration
                        if (Application.Current.Properties["duration"].ToString() != "0")
                        {
                            if (elapsed >= duration)
                            {
                                _recorder.IsRecording = false;
                            }
                        }

                        //Update instructions when user reaches edge of frame
                        if (clippedEdges.HasFlag(FrameEdges.Left))
                        {
                            Instructions.Text = "Turn right and walk";
                            if (current == 2)
                            {
                                laps++;
                            }
                            current = 1;
                        }
                        if (clippedEdges.HasFlag(FrameEdges.Right))
                        {
                            Instructions.Text = "Turn left and walk";
                            if (current == 1)
                            {
                                laps++;
                            }
                            current = 2;
                        }
                        if (laps == 3)  //end of exercise. Save node data
                        {
                            Instructions.Text = "You have completed this exercise!";

                            _timer.Stop();

                            if (!dataSaved)
                            {
                                _recorder.Stop();
                                SaveFileDialog dialog = new SaveFileDialog
                                {
                                    Filter = "Excel files|*.csv"
                                };

                                dialog.ShowDialog();

                                if (!string.IsNullOrWhiteSpace(dialog.FileName))
                                {
                                    System.IO.File.Copy(_recorder.Result, dialog.FileName, true);
                                }

                                //Write data for report generation
                                string path = System.IO.Path.Combine(Environment.CurrentDirectory, @"..\..\..\UserData\WalkingReportData.csv");
                                // This text is added only once to the file.
                                if (!File.Exists(path))
                                {
                                    // Record duration and date of exercise
                                    using (StreamWriter sw = File.CreateText(path))
                                    {
                                        sw.WriteLine("ExerciseDuration,Date");
                                        sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                    }
                                }
                                else
                                {
                                    // This text is always added, making the file longer over time
                                    // if it is not deleted.
                                    using (StreamWriter sw = File.AppendText(path))
                                    {
                                        sw.WriteLine(_timer.Elapsed.ToString() + "," + DateTime.Today.ToString("d"));
                                    }
                                }
                                dataSaved = true;
                            }
                        }
                    }
                }
            }
        }
    private void MyDataFrameReadyEventHandler(object sender, DataFrameReadyEventArgs e)
    {
        using (DataFrame dataFrame = e.OpenFrame() as DataFrame)
        {
            if (dataFrame != null)
            {
                Skeleton skl = dataFrame.Skeletons[0];
                edgeWarnings = skl.ClippedEdges;
                StringBuilder sb = new StringBuilder();
                int warningsCount = CheckEdgeWarnings(sb);

                if (SdkManager.IsDebugRun)
                {
                    Debug.Log(String.Format("Warnings frame: {0}, contains {1} Warnings:\n{2}", dataFrame.FrameKey.FrameNumberKey, warningsCount, sb.ToString()));
                }
            }
        }
    }
Example #14
0
   public static Offset<Body> CreateBody(FlatBufferBuilder builder,
 ulong trackingId = 0,
 bool isTracked = false,
 bool isRestricted = false,
 FrameEdges clippedEdges = FrameEdges.None,
 Offset<Hand> handLeftOffset = default(Offset<Hand>),
 Offset<Hand> handRightOffset = default(Offset<Hand>),
 VectorOffset jointsOffset = default(VectorOffset))
   {
       builder.StartObject(7);
       Body.AddTrackingId(builder, trackingId);
       Body.AddJoints(builder, jointsOffset);
       Body.AddHandRight(builder, handRightOffset);
       Body.AddHandLeft(builder, handLeftOffset);
       Body.AddClippedEdges(builder, clippedEdges);
       Body.AddIsRestricted(builder, isRestricted);
       Body.AddIsTracked(builder, isTracked);
       return Body.EndBody(builder);
   }
Example #15
0
 public static void AddClippedEdges(FlatBufferBuilder builder, FrameEdges clippedEdges)
 {
     builder.AddInt(3, (int)clippedEdges, 0);
 }
 private void UpdateFrameEdges(FrameEdges edges)
 {
     // Using .NET Enum functions to see what Warnings we received
     Right.IsChecked = edges.HasFlag(FrameEdges.Right);
     Near.IsChecked = edges.HasFlag(FrameEdges.Near);
     Left.IsChecked = edges.HasFlag(FrameEdges.Left);
     Far.IsChecked = edges.HasFlag(FrameEdges.Far);
 }