public void _bodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            IEnumerable <IBody> bodies = null; // to make the GetBitmap call a little cleaner

            using (var frame = e.FrameReference.AcquireFrame())
            {
                if (!ReferenceEquals(null, frame))
                {
                    frame.GetAndRefreshBodyData(_bodies);
                    bodies = _bodies;
                }
            }

            if (!ReferenceEquals(null, bodies))
            {
                CameraSpacePoint lastCentralPoint = new CameraSpacePoint();
                foreach (IBody body in bodies)
                {
                    //using only the central point
                    var centralPoint = body.Joints[JointType.SpineMid].Position;
                    if (centralPoint.X != 0 || centralPoint.Y != 0 || centralPoint.Z != 0)
                    {
                        if (lastCentralPoint.X != 0 || lastCentralPoint.Y != 0 || lastCentralPoint.Z != 0)
                        {
                            var distance = Math.Sqrt(
                                Math.Pow(lastCentralPoint.X - centralPoint.X, 2) +
                                Math.Pow(lastCentralPoint.Y - centralPoint.Y, 2) +
                                Math.Pow(lastCentralPoint.Z - centralPoint.Z, 2));


                            CheckPerson.Instance.CheckIfExistsPerson(body.TrackingId);
                            var time = _dataAccessFacade.GetSceneInUseAccess()?.GetLocation();
                            if (time.HasValue)
                            {
                                //_dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Proxemic", "Events", time.Value, distance, false);
                                if (distance < 0.45)
                                {
                                    _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Proxemic", "Events", time.Value, distance, 0);
                                }
                                else if (distance < 0.65)
                                {
                                    _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Proxemic", "Events", time.Value, distance, 1);
                                }
                                else if (distance < 0.85)
                                {
                                    _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Proxemic", "Events", time.Value, distance, 2);
                                }
                                else
                                {
                                    _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Proxemic", "Events", time.Value, distance, 3);
                                }
                                //Console.WriteLine($"Proxemic is: {distance}");
                            }
                        }
                        lastCentralPoint = centralPoint;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Listener of Kinect gesture frames.
        /// </summary>
        /// <param name="sender">The sender object.</param>
        /// <param name="e">The kinect gesture frame.</param>
        public void Gesture_FrameArrived(object sender, KinectGestureFrameArrivedArgs e)
        {
            CheckPerson.Instance.CheckIfExistsPerson(e.TrackingId);
            if (e.Time.HasValue)
            {
                //process discrete gestures
                if (!ReferenceEquals(null, e?.Frame?.DiscreteGestureResults))
                {
                    foreach (var discreteGesture in e.Frame.DiscreteGestureResults)
                    {
                        if (discreteGesture.Value.Detected)
                        {
                            var tuple = new Tuple <Person, string>(CheckPerson.Instance.PersonsId[e.TrackingId], discreteGesture.Key.Name);
                            if (!_discreteGestures.Exists(d => d.Equals(tuple)))
                            {
                                _discreteGestures.Add(tuple);
                            }
                            //check in the variable if has processed, if not, check in the database and then add it to variable
                            if (!_processedDiscreteGestureNames.Exists(pd => pd.Equals(discreteGesture.Key.Name)))
                            {
                                _dataAccessFacade.GetSubModalAccess().AddIfNotExists("Discrete Posture", discreteGesture.Key.Name, "Autogenerated", null);
                                _processedDiscreteGestureNames.Add(discreteGesture.Key.Name);
                            }
                            if (discreteGesture.Value.Detected)
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[e.TrackingId], "Discrete Posture", discreteGesture.Key.Name, e.Time.Value, discreteGesture.Value.Confidence, 1);
                            }
                            else
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[e.TrackingId], "Discrete Posture", discreteGesture.Key.Name, e.Time.Value, discreteGesture.Value.Confidence, -1);
                            }
                        }
                    }
                }

                //process continuous gestures
                if (!ReferenceEquals(null, e?.Frame?.ContinuousGestureResults))
                {
                    foreach (var continuousGesture in e.Frame.ContinuousGestureResults)
                    {
                        //check in the variable if has processed, if not, check in the database and then add it to variable
                        if (!_processedDiscreteGestureNames.Exists(pd => pd.Equals(continuousGesture.Key.Name)))
                        {
                            _dataAccessFacade.GetSubModalAccess().AddIfNotExists("Continuous Posture", continuousGesture.Key.Name, "Autogenerated", null);
                            _processedDiscreteGestureNames.Add(continuousGesture.Key.Name);
                        }
                        _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[e.TrackingId], "Continuous Posture", continuousGesture.Key.Name, e.Time.Value, continuousGesture.Value.Progress, -1);
                    }
                }
            }
        }
Exemple #3
0
        public void _audioBeamReader_FrameArrived(object sender, AudioBeamFrameArrivedEventArgs e)
        {
            var frames = e.FrameReference.AcquireBeamFrames();

            if (ReferenceEquals(null, frames))
            {
                return;
            }

            foreach (var frame in frames)
            {
                if (ReferenceEquals(null, frame) || ReferenceEquals(null, frame.SubFrames))
                {
                    return;
                }
                foreach (var subFrame in frame.SubFrames)
                {
                    if (ReferenceEquals(null, subFrame.AudioBodyCorrelations))
                    {
                        return;
                    }
                    foreach (var audioBodyCorrelation in subFrame.AudioBodyCorrelations)
                    {
                        CheckPerson.Instance.CheckIfExistsPerson(audioBodyCorrelation.BodyTrackingId);
                        var time = _dataAccessFacade.GetSceneInUseAccess()?.GetLocation();
                        if (time.HasValue)
                        {
                            _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[audioBodyCorrelation.BodyTrackingId], "Voice", "Talked", time.Value, 1);
                        }

                        //Console.WriteLine("Tiempo: {0}, Llegó Voz de {1}", DateTime.Now, audioBodyCorrelation.BodyTrackingId);
                    }
                }
            }
        }
Exemple #4
0
        public void _bodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            IEnumerable <IBody> bodies = null; // to make the GetBitmap call a little cleaner

            using (var frame = e.FrameReference.AcquireFrame())
            {
                if (!ReferenceEquals(null, frame))
                {
                    frame.GetAndRefreshBodyData(_bodies);
                    bodies = _bodies;
                }
            }

            if (!ReferenceEquals(null, bodies))
            {
                foreach (IBody body in bodies)
                {
                    try
                    {
                        var left  = body.Joints[JointType.ShoulderLeft].Position;
                        var right = body.Joints[JointType.ShoulderRight].Position;
                        var spine = body.Joints[JointType.SpineShoulder].Position;

                        var v1 = new double[]
                        {
                            spine.X - left.X + _movementToPositive,
                            spine.Y - left.Y + _movementToPositive,
                            spine.Z - left.Z + _movementToPositive
                        };

                        var v2 = new double[]
                        {
                            right.X - spine.X + _movementToPositive,
                            right.Y - spine.Y + _movementToPositive,
                            right.Z - spine.Z + _movementToPositive
                        };

                        //The dot product of v1 and v2 is a function of
                        //the cosine of the angle between them
                        //(it's scaled by the product of their magnitudes).
                        //So first normalize v1 and v2
                        var v1mag  = Math.Sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
                        var v1norm = new double[] { v1[0] / v1mag, v1[1] / v1mag, v1[2] / v1mag };

                        var v2mag  = Math.Sqrt(v2[0] * v2[0] + v2[1] * v2[1] + v2[2] * v2[2]);
                        var v2norm = new double[] { v2[0] / v2mag, v2[1] / v2mag, v2[2] / v2mag };

                        //Then calculate the dot product:
                        var res = v1norm[0] * v2norm[0] + v1norm[1] * v2norm[1] + v1norm[2] * v2norm[2];

                        //And finally, recover the angle:
                        var angle = Math.Acos(res) * 180.0 / Math.PI;
                        if (!double.IsNaN(angle) && !double.IsInfinity(angle))
                        {
                            CheckPerson.Instance.CheckIfExistsPerson(body.TrackingId);
                            var time = _dataAccessFacade.GetSceneInUseAccess()?.GetLocation();
                            if (time.HasValue)
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Shoulders", "Angle", time.Value, angle, -1);
                                //Console.WriteLine($"El ángulo de los hombros es: {angle}");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine($"Exception obtained at try get shoulders angle: {ex.Message}");
                    }
                }
            }
        }
        public void _bodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            IEnumerable <IBody> bodies = null; // to make the GetBitmap call a little cleaner

            using (var frame = e.FrameReference.AcquireFrame())
            {
                if (!ReferenceEquals(null, frame))
                {
                    frame.GetAndRefreshBodyData(_bodies);
                    bodies = _bodies;
                }
            }

            if (!ReferenceEquals(null, bodies))
            {
                foreach (IBody body in bodies)
                {
                    var orientation = body.JointOrientations[JointType.Neck].Orientation;

                    var rotationX = orientation.Pitch();
                    var rotationY = orientation.Yaw();
                    var rotationZ = orientation.Roll();
                    if (rotationX != 0 || rotationY != 0 || rotationZ != 0)
                    {
                        CheckPerson.Instance.CheckIfExistsPerson(body.TrackingId);
                        var time = _dataAccessFacade.GetSceneInUseAccess()?.GetLocation();
                        if (time.HasValue)
                        {
                            _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Neck Orientation", "Pitch", time.Value, rotationX, -1);
                            //_dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Neck Orientation", "Yaw", time.Value, rotationY, false);
                            _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Neck Orientation", "Roll", time.Value, rotationZ, -1);

                            _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Lean", "X", time.Value, body.Lean.X, -1);
                            //_dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Lean", "Y", time.Value, body.Lean.Y, false);

                            if (body.Lean.Y < (2 / 3) - 1) //between -1 and -0.333
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Lean", "Y", time.Value, body.Lean.Y, 0);
                            }
                            else if (body.Lean.Y < 1 - (2 / 3)) //between -0.333 and 0.333
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Lean", "Y", time.Value, body.Lean.Y, 1);
                            }
                            else //between 0.333 and 1
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Lean", "Y", time.Value, body.Lean.Y, 2);
                            }

                            //Console.WriteLine($"XPitch: {rotationX}\tYYaw: {rotationY}\tZRoll: {rotationZ}");
                            //Console.WriteLine($"XLean: {body.Lean.X}\tYLean: {body.Lean.Y}");

                            //2 is because the horizontal max y 4 mts
                            double distanceMaxOfBorder = 2 + Math.Abs(body.Joints[JointType.Neck].Position.X);
                            //4.3 is the distance between the public and the person
                            Console.WriteLine($"The distance between the sensor and person is: {body.Joints[JointType.Neck].Position.Z}");
                            double hipoten = Math.Sqrt(distanceMaxOfBorder * distanceMaxOfBorder + 4.3 * 4.3);
                            double angle   = Math.Asin(distanceMaxOfBorder / hipoten);
                            if (rotationY <= angle)
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Neck Orientation", "Yaw", time.Value, body.Lean.Y, 0);
                            }
                            else
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "Neck Orientation", "Yaw", time.Value, body.Lean.Y, -1);
                            }
                        }
                    }
                }
            }
        }
        public void _bodyReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            IEnumerable <IBody> bodies = null; // to make the GetBitmap call a little cleaner

            using (var frame = e.FrameReference.AcquireFrame())
            {
                if (!ReferenceEquals(null, frame))
                {
                    frame.GetAndRefreshBodyData(_bodies);
                    bodies = _bodies;
                }
            }

            if (!ReferenceEquals(null, bodies))
            {
                List <CameraSpacePoint> lastPersonsJoints = new List <CameraSpacePoint>();
                foreach (IBody body in bodies)
                {
                    //using all points
                    List <CameraSpacePoint> actualPersonJoints = new List <CameraSpacePoint>();
                    double minDistance = double.PositiveInfinity;
                    foreach (var joint in body.Joints)
                    {
                        if (joint.Value.Position.X != 0 || joint.Value.Position.Y != 0 || joint.Value.Position.Z != 0)
                        {
                            actualPersonJoints.Add(joint.Value.Position);
                            foreach (var lastJoint in lastPersonsJoints)
                            {
                                var distance = Math.Sqrt(
                                    Math.Pow(lastJoint.X - joint.Value.Position.X, 2) +
                                    Math.Pow(lastJoint.Y - joint.Value.Position.Y, 2) +
                                    Math.Pow(lastJoint.Z - joint.Value.Position.Z, 2));
                                if (distance < minDistance)
                                {
                                    minDistance = distance;
                                }
                            }
                        }
                    }
                    if (actualPersonJoints.Count > 0)
                    {
                        lastPersonsJoints = actualPersonJoints;
                    }
                    if (!double.IsInfinity(minDistance))
                    {
                        CheckPerson.Instance.CheckIfExistsPerson(body.TrackingId);
                        var time = _dataAccessFacade.GetSceneInUseAccess()?.GetLocation();
                        if (time.HasValue)
                        {
                            //_dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "AccProxemic", "Events", time.Value, minDistance, false);
                            if (minDistance < 0.45)
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "AccProxemic", "Events", time.Value, minDistance, 0);
                            }
                            else if (minDistance < 0.65)
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "AccProxemic", "Events", time.Value, minDistance, 1);
                            }
                            else if (minDistance < 0.85)
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "AccProxemic", "Events", time.Value, minDistance, 2);
                            }
                            else
                            {
                                _dataAccessFacade.GetEventAccess().Add(CheckPerson.Instance.PersonsId[body.TrackingId], "AccProxemic", "Events", time.Value, minDistance, 3);
                            }
                            //Console.WriteLine($"Proxemic real min is: {minDistance}");
                        }
                    }
                }
            }
        }
        public void DataReceiver(object sender, EegFrameArrivedEventArgs e)
        {
            //if samplingHz is 128, then alternates if the signal is processed or no
            if (EEGEmoProc2ChSettings.Instance.SamplingHz == 256)
            {
                _signalGet = true;
            }
            else if (EEGEmoProc2ChSettings.Instance.SamplingHz == 128)
            {
                _signalGet = !_signalGet;
            }


            double[] values         = new double[2];
            var      channelCounter = 0;

            foreach (var channel in e.Channels)
            {
                if (channel.Position.Equals("F3"))
                {
                    if (EEGEmoProc2ChSettings.Instance.SamplingHz == 256)
                    {
                        values[0] = channel.Value;
                    }
                    else if (_signalGet)
                    {
                        values[0] = (lastF3 + channel.Value) / 2;
                    }
                    else
                    {
                        lastF3 = channel.Value;
                    }
                    channelCounter++;
                }
                if (channel.Position.Equals("C4"))
                {
                    if (EEGEmoProc2ChSettings.Instance.SamplingHz == 256)
                    {
                        values[1] = channel.Value;
                    }
                    else if (_signalGet)
                    {
                        values[1] = (lastC4 + channel.Value) / 2;
                    }
                    else
                    {
                        lastC4 = channel.Value;
                    }
                    channelCounter++;
                }
            }
            if (channelCounter == 2)
            {
                _signaList.Add(values);
            }

            //if the window ends, sends the signal to process
            var sceneLocation = e.Time;

            if (_signaList.Count >= 0 &&
                _lastSecond != (int)sceneLocation.TotalSeconds &&
                (int)sceneLocation.TotalSeconds % 9 == 0)
            {
                _lastSecond = (int)sceneLocation.TotalSeconds;

                try
                {
                    var tag = LearningModel.Classify(_signaList);
                    Console.WriteLine(tag.ToString());
                    _dataAccessFacade.GetEventAccess().Add(e.Person, "Emotion", tag.ToString(), e.Time, 1);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("error: " + ex.Message);
                }
                _signaList = new List <double[]>();
            }
        }