Esempio n. 1
0
 /// <summary>
 /// Cancel the current face capture operation
 /// </summary>
 private void StopCollecting()
 {
     if (this.faceModelBuilder != null)
     {
         this.faceModelBuilder.Dispose();
         this.faceModelBuilder = null;
     }
 }
Esempio n. 2
0
        /// <summary>
        /// This event fires when the face capture operation is completed
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void HdFaceBuilder_CollectionCompleted(object sender, FaceModelBuilderCollectionCompletedEventArgs e)
        {
            Log.LogMessage("FaceTracking complete");
            if (OnAskIfCaptured != null)
                OnAskIfCaptured(true, true, true, true, true);

            var modelData = e.ModelData;

            this.currentFaceModel = modelData.ProduceFaceModel();

            this.faceModelBuilder.Dispose();
            this.faceModelBuilder = null;

            //The kinect is done preparing here.
        }
Esempio n. 3
0
        /// <summary>
        /// This event is fired when a tracking is lost for a body tracked by HDFace Tracker
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void HdFaceSource_TrackingIdLost(object sender, TrackingIdLostEventArgs e)
        {
            var lostTrackingID = e.TrackingId;

            if (this.currentTrackingId == lostTrackingID)
            {
                this.currentTrackingId = 0;
                this.currentTrackedBody = null;
                if (this.faceModelBuilder != null)
                {
                    this.faceModelBuilder.Dispose();
                    this.faceModelBuilder = null;
                }

                this.highDefinitionFaceFrameSource.TrackingId = 0;
            }
        }
Esempio n. 4
0
 private void Window_Closing( object sender, System.ComponentModel.CancelEventArgs e )
 {
     if ( faceModelBuilder != null ) {
         faceModelBuilder.Dispose();
         faceModelBuilder = null;
     }
     if ( hdFaceFrameReader != null ) {
         hdFaceFrameReader.Dispose();
         hdFaceFrameReader = null;
     }
     if ( bodyFrameReader != null ) {
         bodyFrameReader.Dispose();
         bodyFrameReader = null;
     }
     if ( faceModel!=null ) {
         faceModel.Dispose();
         faceModel = null;
     }
     if ( kinect != null ) {
         kinect.Close();
         kinect = null;
     }
 }
Esempio n. 5
0
        public void StartCollecting()
        {
            this.StopCollecting();

            this.faceModelBuilder = this.highDefinitionFaceFrameSource.OpenModelBuilder(FaceModelBuilderAttributes.None);

            this.faceModelBuilder.BeginFaceDataCollection();

            this.faceModelBuilder.CollectionCompleted += this.HdFaceBuilder_CollectionCompleted;
        }
Esempio n. 6
0
        void faceModelBuilder_CollectionCompleted( object sender, FaceModelBuilderCollectionCompletedEventArgs e )
        {
            var modelData = e.ModelData;
            faceModel = modelData.ProduceFaceModel();
            produced = true;

            faceModelBuilder.Dispose();
            faceModelBuilder = null;
        }
Esempio n. 7
0
        private void InitializeHDFace()
        {
            hdFaceFrameSource = new HighDefinitionFaceFrameSource( kinect );
            if ( hdFaceFrameSource==null ) {
                throw new Exception( "Cannot create HD Face Frame Source" );
            }
            hdFaceFrameReader = hdFaceFrameSource.OpenReader();
            hdFaceFrameReader.FrameArrived += hdFaceFrameReader_FrameArrived;
            faceModel = new FaceModel();
            faceAlignment = new FaceAlignment();

            FaceModelBuilderAttributes attributes = FaceModelBuilderAttributes.None;
            faceModelBuilder = hdFaceFrameSource.OpenModelBuilder( attributes );
            if ( faceModelBuilder==null ) {
                throw new Exception( "Cannot open Face Model Builder" );
            }
            faceModelBuilder.BeginFaceDataCollection();
            faceModelBuilder.CollectionCompleted += faceModelBuilder_CollectionCompleted;
        }
        /// <summary>
        /// センサーから骨格データを受け取り処理します
        /// </summary>
        private void OnMultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            var frame = e.FrameReference.AcquireFrame();
            if (frame == null) return;

            // BodyFrameに関してフレームを取得する
            using (var bodyFrame = frame.BodyFrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    if (bodies == null)
                        bodies = new Body[bodyFrame.BodyCount];

                    // 骨格データを格納
                    bodyFrame.GetAndRefreshBodyData(bodies);

                    // FaceTrackingが開始されていないか確認
                    if (!this.hdFaceFrameSource.IsTrackingIdValid)
                    {
                        // トラッキング先の骨格を選択

                        var target = (from body in this.bodies where body.IsTracked select body).FirstOrDefault();
                        if (target != null)
                        {
                            // 検出されたBodyに対してFaceTrackingを行うよう、FaceFrameSourceを設定
                            hdFaceFrameSource.TrackingId = target.TrackingId;
                            // FaceModelBuilderを初期化
                            if (this.faceModelBuilder != null)
                            {
                                this.faceModelBuilder.Dispose();
                                this.faceModelBuilder = null;
                            }
                            this.faceModelBuilder = this.hdFaceFrameSource.OpenModelBuilder(DefaultAttributes);
                            // FaceModelBuilderがモデルの構築を完了した時に発生するイベント
                            this.faceModelBuilder.CollectionCompleted += this.OnModelBuilderCollectionCompleted;
                            // FaceModelBuilderの状態を報告するイベント
                            this.faceModelBuilder.CaptureStatusChanged += faceModelBuilder_CaptureStatusChanged;
                            this.faceModelBuilder.CollectionStatusChanged += faceModelBuilder_CollectionStatusChanged;

                            // キャプチャの開始
                            this.faceModelBuilder.BeginFaceDataCollection();
                        }
                    }
                }
            }
        }
        /// <summary>
        /// FaceModelBuilderがモデルの構築を完了したときのイベントを処理します
        /// </summary>
        private void OnModelBuilderCollectionCompleted(object sender, FaceModelBuilderCollectionCompletedEventArgs e)
        {
            var modelData = e.ModelData;
            this.faceModel = modelData.ProduceFaceModel();
            
            // MeshをUpdate
            UpdateMesh();

            // SkinColorとHairColorの値も更新
            this.SkinColor = UIntToColor(this.faceModel.SkinColor);
            this.HairColor = UIntToColor(this.faceModel.HairColor);
            
            // 更新を行う
            this.FaceModelBuilderStatus = GetCollectionStatus(((FaceModelBuilder)sender).CollectionStatus);
            this.FaceModelCaptureStatus = ((FaceModelBuilder)sender).CaptureStatus.ToString();

            this.faceModelBuilder.Dispose();
            this.faceModelBuilder = null;
        }
 /// <summary>
 /// Cancel the current face capture operation
 /// </summary>
 private void StopFaceCapture()
 {
     if (this.faceModelBuilder != null)
     {
         this.faceModelBuilder.Dispose();
         this.faceModelBuilder = null;
     }
 }
        /*
        private void keepGazeTrack(bool looking){
            Console.Write(looking+"\n");

            if (!looking)
            {
                if ((timer2 - timer1 > 1000))
                {
                    player.SoundLocation = soundDirectory + "sounds\\alert.wav";
                    player.Play();
                }
            }
            else
                timer1 = timer2;
        }
        */
        /// <summary>
        /// Start a face capture operation
        /// </summary>
        private void StartCapture()
        {
            this.StopFaceCapture();

            this.faceModelBuilder = null;

            this.faceModelBuilder = this.highDefinitionFaceFrameSource.OpenModelBuilder(FaceModelBuilderAttributes.None);

            this.faceModelBuilder.BeginFaceDataCollection();

            this.faceModelBuilder.CollectionCompleted += this.HdFaceBuilder_CollectionCompleted;
        }
        /// <summary>
        /// This event fires when the face capture operation is completed
        /// </summary>
        /// <param name="sender">object sending the event</param>
        /// <param name="e">event arguments</param>
        private void HdFaceBuilder_CollectionCompleted(object sender, FaceModelBuilderCollectionCompletedEventArgs e)
        {
            var modelData = e.ModelData;

            this.currentFaceModel = modelData.ProduceFaceModel();

            this.faceModelBuilder.Dispose();
            this.faceModelBuilder = null;

            this.CurrentBuilderStatus = "Capture Complete";
        }
        /// <summary>
        /// Disposes the face model builder
        /// </summary>
        private void DisposeFaceModelBuilder()
        {
            var localFmb = this.fmb;
            this.fmb = null;

            if (localFmb != null)
            {
                localFmb.CollectionCompleted -= this.FaceModelBuilderCollectionCompleted;
                localFmb.Dispose();
            }
        }
        /// <summary>
        /// Handles face frame updates
        /// </summary>
        private void FaceFrameArrived(object sender, HighDefinitionFaceFrameArrivedEventArgs e)
        {
            ulong? newTrackingId = null;

            using (var frame = e.FrameReference.AcquireFrame())
            {
                if (frame != null)
                {
                    if (frame.IsTrackingIdValid && frame.IsFaceTracked)
                    {
                        frame.GetAndRefreshFaceAlignmentResult(this.faceAlignment);
                        this.faceModel = frame.FaceModel;
                        newTrackingId = frame.TrackingId;
                    }
                }
            }

            if (this.Processors.Any(x => x.RequiresFaceModelBuilder) && newTrackingId.HasValue && this.currentTrackingId != newTrackingId)
            {
                lock (this.processFaceModelMutex)
                {
                    this.currentTrackingId = newTrackingId;
                    this.faceModel = null;
                    this.constructedFaceModel = null;
                    this.DisposeFaceModelBuilder();
                    this.fmb = this.faceSource.OpenModelBuilder(FaceModelBuilderAttributes.HairColor | FaceModelBuilderAttributes.SkinColor);
                    this.fmb.BeginFaceDataCollection();
                    this.fmb.CollectionCompleted += this.FaceModelBuilderCollectionCompleted;
                }
            }

            lock (this)
            {
                this.faceReady = true;
                this.StartWorkerIfReady();
            }
        }