Exemplo n.º 1
0
 public void addHDData(FaceHD f)
 {
     _hd_list.AddLast(f);
     while (f.time.Subtract(_hd_list.First().time) > span)
     {
         _hd_list.RemoveFirst();
     }
 }
Exemplo n.º 2
0
        public MainPage()
        {
            this.InitializeComponent();
            _sensor   = KinectSensor.GetDefault();
            _faceData = new FaceData();

            if (_sensor != null)
            {
                _sensor.Open();

                _bodies = new Body[_sensor.BodyFrameSource.BodyCount];

                //_colorReader = _sensor.ColorFrameSource.OpenReader();
                //_colorReader.FrameArrived += ColorReader_FrameArrived;
                _bodyReader = _sensor.BodyFrameSource.OpenReader();
                _bodyReader.FrameArrived += BodyReader_FrameArrived;

                // 2) Initialize the face source with the desired features

                // specify the required face frame results

                FaceFrameFeatures faceFrameFeatures =
                    FaceFrameFeatures.BoundingBoxInColorSpace
                    | FaceFrameFeatures.PointsInColorSpace
                    | FaceFrameFeatures.RotationOrientation
                    | FaceFrameFeatures.FaceEngagement
                    | FaceFrameFeatures.Glasses
                    | FaceFrameFeatures.Happy
                    | FaceFrameFeatures.LeftEyeClosed
                    | FaceFrameFeatures.RightEyeClosed
                    | FaceFrameFeatures.LookingAway
                    | FaceFrameFeatures.MouthMoved
                    | FaceFrameFeatures.MouthOpen;

                _normalFaceSource = new FaceFrameSource(_sensor, 0, faceFrameFeatures);
                _normalFaceReader = _normalFaceSource.OpenReader();
                _normalFaceReader.FrameArrived += NormalFaceReader_FrameArrived;


                // from HD
                _hdFaceSource = new HighDefinitionFaceFrameSource(_sensor);

                _hdFaceReader = _hdFaceSource.OpenReader();
                _hdFaceReader.FrameArrived += HDFaceReader_FrameArrived;

                _faceModel     = new FaceModel();
                _faceAlignment = new FaceAlignment();
            }

            //tmp canvas

            /*
             * // Add a Line Element
             * var myLine = new Line();
             * // myLine.Stroke = System.Windows.Media.Brushes.LightSteelBlue;
             * myLine.Stroke = new SolidColorBrush(Colors.Blue);
             * //myLine.Stroke =
             *
             * myLine.X1 = 100;
             * myLine.X2 = 150;
             * myLine.Y1 = 100;
             * myLine.Y2 = 150;
             * myLine.HorizontalAlignment = HorizontalAlignment.Left;
             * myLine.VerticalAlignment = VerticalAlignment.Center;
             * myLine.StrokeThickness = 2;
             * canvasHD.Children.Add(myLine);
             */
            // tmp
            write_log("llllllllllooooooooooooooooooonnnnnnnnnnnnnnnnnnnnnggggggggggggggg");
            write_log(FaceHD.MouthUpperlipMidbottom.ToString());
            var face = new FaceHD();

            write_log(face.dump_str());

            emoji.Source = Emoji.none;

            var autoEvent = new AutoResetEvent(false);

            //tmp.Text = "tmp";
            var stateTimer = new Timer(tmp_callback, autoEvent, 1000, 1000);
            //var stateTimer = new Timer(tmp_callback);
            //var timer = new System.Timers.Timer(1000);
        }
Exemplo n.º 3
0
        private void UpdateFacePoints()
        {
            if (_faceModel == null)
            {
                return;
            }

            var vertices = _faceModel.CalculateVerticesForAlignment(_faceAlignment);

            if (vertices.Count > 0)
            {
                if (_points.Count == 0)
                {
                    for (int index = 0; index < vertices.Count; index++)
                    {
                        var mycolor  = Colors.Blue;
                        var mywidth  = 2.0;
                        var myheight = 2.0;

                        //if (index == 91 || index == 687 || index == 19 || index == 1072 || index == 10 || index == 8) {
                        if (FaceHD.isMouthPoint(index))
                        {
                            mycolor  = Colors.Red;
                            mywidth  = 20.0;
                            myheight = 20.0;
                        }
                        else if (index == FaceHD.LeftcheekCenter || index == FaceHD.RightcheekCenter)
                        {
                            mycolor  = Colors.Green;
                            mywidth  = 20.0;
                            myheight = 20.0;
                        } /*else if (index == FaceHD.NoseBottom)
                           * {
                           * mycolor = Colors.Black;
                           * mywidth = 20.0;
                           * myheight = 20.0;
                           * }*/
                          /*else if (Face.isLeftEyePoint(index)) {
                           * mycolor = Colors.Green;
                           * mywidth = 20.0;
                           * myheight = 20.0;
                           * } else if (Face.isRightEyePoint(index)) {
                           * mycolor = Colors.Purple;
                           * mywidth = 20.0;
                           * myheight = 20.0;
                           * }*/

                        Ellipse ellipse = new Ellipse
                        {
                            Width  = mywidth,
                            Height = myheight,
                            Fill   = new SolidColorBrush(mycolor)
                        };

                        _points.Add(ellipse);
                    }

                    foreach (Ellipse ellipse in _points)
                    {
                        canvas.Children.Add(ellipse);
                        //canvasHD.Children.Add(ellipse);
                    }
                }

                var face = new FaceHD();


                for (int index = 0; index < vertices.Count; index++)
                //for (int i = 0; i < _target_points.Length; i++)
                {
                    //var index = _target_points[i];
                    CameraSpacePoint vertice = vertices[index];
                    //DepthSpacePoint d_point = _sensor.CoordinateMapper.MapCameraPointToDepthSpace(vertice);
                    ColorSpacePoint point = _sensor.CoordinateMapper.MapCameraPointToColorSpace(vertice);

                    if (float.IsInfinity(point.X) || float.IsInfinity(point.Y))
                    {
                        return;
                    }

                    Ellipse ellipse = _points[index];

                    Canvas.SetLeft(ellipse, point.X);
                    Canvas.SetTop(ellipse, point.Y);

                    face.addData(index, vertice.X, vertice.Y, vertice.Z);
                }

                //write_log(face.dump_str());
                _faceData.addHDData(face);
                info.Text  = face.dump_str();
                info.Text += _faceData.dump_str();
            }
        }