Esempio n. 1
0
        private void SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            // Speech utterance confidence below which we treat speech as if it hadn't been heard
            const double ConfidenceThreshold = 0.75; //0.35


            if (e.Result.Confidence >= ConfidenceThreshold)
            {
                switch (e.Result.Semantics.Value.ToString())
                {
                case "HELP":
                    MessageBox.Show("The patient might need HELP");
                    alarmCount++;
                    this.alarmCountText.Text = Convert.ToString(alarmCount);

                    using (MasterEntities context = new MasterEntities())
                    {
                        var alarm = new TotalAlarm()
                        {
                            Date = DateTime.Now
                        };
                        context.TotalAlarms.Add(alarm);
                        context.SaveChanges();


                        //Retrieve data from stored procedure
                        var alarms = context.GetTotalAlarms();

                        foreach (var x in alarms)
                        {
                            this.totalAlarms.Text = Convert.ToString(x.Value);
                        }
                    }

                    break;

                case "PLEASE HELP":
                    MessageBox.Show("Alarm!! Patient just said PLEASE HELP!!!");
                    alarmCount++;
                    this.alarmCountText.Text = Convert.ToString(alarmCount);

                    using (MasterEntities context = new MasterEntities())
                    {
                        var alarm = new TotalAlarm()
                        {
                            Date = DateTime.Now
                        };
                        context.TotalAlarms.Add(alarm);
                        context.SaveChanges();


                        //Retrieve data from stored procedure
                        var alarms = context.GetTotalAlarms();

                        foreach (var x in alarms)
                        {
                            this.totalAlarms.Text = Convert.ToString(x.Value);
                        }
                    }

                    break;


                case "AMBULANCE":
                    MessageBox.Show("The patient needs an AMBULANCE...");
                    alarmCount++;
                    this.alarmCountText.Text = Convert.ToString(alarmCount);

                    using (MasterEntities context = new MasterEntities())
                    {
                        var alarm = new TotalAlarm()
                        {
                            Date = DateTime.Now
                        };
                        context.TotalAlarms.Add(alarm);
                        context.SaveChanges();


                        //Retrieve data from stored procedure
                        var alarms = context.GetTotalAlarms();

                        foreach (var x in alarms)
                        {
                            this.totalAlarms.Text = Convert.ToString(x.Value);
                        }
                    }

                    break;

                case "POLICE":
                    MessageBox.Show("The patient calls for police...");
                    alarmCount++;
                    this.alarmCountText.Text = Convert.ToString(alarmCount);

                    using (MasterEntities context = new MasterEntities())
                    {
                        var alarm = new TotalAlarm()
                        {
                            Date = DateTime.Now
                        };
                        context.TotalAlarms.Add(alarm);
                        context.SaveChanges();


                        //Retrieve data from stored procedure
                        var alarms = context.GetTotalAlarms();

                        foreach (var x in alarms)
                        {
                            this.totalAlarms.Text = Convert.ToString(x.Value);
                        }
                    }

                    break;

                default:
                    Console.WriteLine("Default case");
                    break;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the body frame data arriving from the sensor and updates the associated gesture detector object.
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            bool dataReceived = false;

            using (var bodyFrame = this.bodyFrameReader.AcquireLatestFrame())
            {
                if (bodyFrame != null)
                {
                    if (this.bodies == null)
                    {
                        // creates an array of 6 bodies, which is the max number of bodies that Kinect can track simultaneously
                        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);

                    if (!this.bodies[this.activeBodyIndex].IsTracked)
                    {
                        // we lost tracking of the active body, so update to the first tracked body in the array
                        int bodyIndex = this.GetActiveBodyIndex();

                        if (bodyIndex > 0)
                        {
                            this.activeBodyIndex = bodyIndex;
                        }
                    }

                    dataReceived = true;
                }
            }

            if (dataReceived)
            {
                Body activeBody = this.bodies[this.activeBodyIndex];

                // visualize the new body data
                this.kinectBodyView.UpdateBodyFrame(activeBody);

                // visualize the new gesture data
                if (activeBody.TrackingId != this.gestureDetector.TrackingId)
                {
                    // if the tracking ID changed, update the detector with the new value
                    this.gestureDetector.TrackingId = activeBody.TrackingId;
                }

                if (this.gestureDetector.TrackingId == 0)
                {
                    // the active body is not tracked, pause the detector and update the UI
                    this.gestureDetector.IsPaused = true;
                    this.gestureResultView.UpdateGestureResult(false, false, false, 0.0f, 0.0f, -1.0f);
                }
                else
                {
                    // the active body is tracked, unpause the detector
                    this.gestureDetector.IsPaused = false;

                    // get the latest gesture frame from the sensor and updates the UI with the results
                    this.gestureDetector.UpdateGestureData();


                    //****mobility
                    if (activeBody.IsTracked && this.gestureDetector.GestureResultView.ConfidenceSeated > 0.8f && this.gestureDetector.GestureResultView.DetectedSeated)
                    {
                        using (MasterEntities context = new MasterEntities())
                        {
                            var pacient = new PacientInfo()
                            {
                                Confidence = this.gestureDetector.GestureResultView.ConfidenceSeated,
                                Seated     = this.gestureDetector.GestureResultView.DetectedSeated.ToString(),
                                Date       = DateTime.Now
                            };

                            context.PacientInfoes.Add(pacient);
                            context.SaveChanges();
                        }
                    }

                    //****drinking
                    if (activeBody.IsTracked && this.gestureDetector.GestureResultView.ConfidenceDrinking > 0.5f && this.gestureDetector.GestureResultView.DetectedDrinking)
                    {
                        using (MasterEntities context = new MasterEntities())
                        {
                            var drinkinginfo = new PacientDrinkingInfo()
                            {
                                Confidence       = this.gestureDetector.GestureResultView.ConfidenceDrinking,
                                Drinking         = this.gestureDetector.GestureResultView.DetectedDrinking.ToString(),
                                DrinkingProgress = this.gestureDetector.GestureResultView.DrinkingProgress,
                                Date             = DateTime.Now
                            };

                            context.PacientDrinkingInfoes.Add(drinkinginfo);
                            context.SaveChanges();
                        }
                    }
                }
            }
        }