示例#1
0
        //顔のフレームの更新処理
        private void updateFaceFrame()
        {
            // フレームデータを取得する
            PXCMCapture.Sample sample = senceManager.QuerySample();
            UpdateColorImage(sample.color);

            //SenceManagerモジュールの顔のデータを更新する
            faceData.Update();

            //検出した顔の数を取得する
            int numFaces = faceData.QueryNumberOfDetectedFaces();

            if (senceManager != null)
            {
                //それぞれの顔ごとに情報取得および描画処理を行う
                for (int i = 0; i < numFaces; ++i)
                {
                    //顔の情報を取得する
                    PXCMFaceData.Face face = faceData.QueryFaceByIndex(i);

                    // 顔の位置を取得:Depthで取得する
                    var detection = face.QueryDetection();
                    if (detection != null)
                    {
                        PXCMRectI32 faceRect;
                        detection.QueryBoundingRect(out faceRect);

                        //顔の位置に合わせて長方形を変更
                        TranslateTransform transform = new TranslateTransform(faceRect.x, faceRect.y);
                        rect[i].Width           = faceRect.w;
                        rect[i].Height          = faceRect.h;
                        rect[i].Stroke          = Brushes.Blue;
                        rect[i].StrokeThickness = 3;
                        rect[i].RenderTransform = transform;

                        //追加:心拍に関する顔の情報を取得する
                        PXCMFaceData.PulseData pulse = face.QueryPulse();
                        if (pulse != null)
                        {
                            //顔の位置に合わせて心拍数を表示
                            tb[i].RenderTransform = new TranslateTransform(transform.X, transform.Y - 30);

                            //追加:心拍数の表示
                            float hrate = pulse.QueryHeartRate();
                            tb[i].Text = "HeartRate:" + hrate;
                        }
                    }
                }
            }
        }
示例#2
0
        private void updateFaceFrame()
        {
            PXCMCapture.Sample sample = this.senseManager.QuerySample();
            this.image = sample.color;

            if (this.image != null)
            {
                this.invalidate = true;
            }

            this.faceData.Update();

            // get number of faces
            FOutFaceLandmarkPoints.SliceCount    = 0;
            FOutFaceExpressionsResult.SliceCount = 0;
            int numFaces = this.faceData.QueryNumberOfDetectedFaces();

            for (int i = 0; i < numFaces; ++i)
            {
                // get faces info
                PXCMFaceData.Face face = this.faceData.QueryFaceByIndex(i);

                // get face position by Depth
                var detection = face.QueryDetection();
                if (detection != null)
                {
                    // detection
                    PXCMRectI32 faceRect;
                    detection.QueryBoundingRect(out faceRect);
                    int sliceCount = i + 1;
                    FOutFacePosition.SliceCount = sliceCount;
                    FOutFacePosition[i]         = new Vector2D(faceRect.x, faceRect.y);
                    FOutFaceWidth.SliceCount    = sliceCount;
                    FOutFaceWidth[i]            = faceRect.w;
                    FOutFaceHeight.SliceCount   = sliceCount;
                    FOutFaceHeight[i]           = faceRect.h;

                    // pose(only use Depth mode)
                    PXCMFaceData.PoseData pose = face.QueryPose();
                    if (pose != null)
                    {
                        // faces angle
                        PXCMFaceData.PoseEulerAngles poseAngle = new PXCMFaceData.PoseEulerAngles();
                        pose.QueryPoseAngles(out poseAngle);
                        FOutFacePose.SliceCount = sliceCount;
                        FOutFacePose[i]         = new Vector3D(poseAngle.pitch, poseAngle.yaw, poseAngle.roll);
                    }

                    // landmarks
                    PXCMFaceData.LandmarksData landmarks = face.QueryLandmarks();
                    FOutFaceLandmarkBinSize.SliceCount = sliceCount;
                    if (landmarks != null)
                    {
                        // number of feature points from landmarks
                        int numPoints = landmarks.QueryNumPoints();
                        FOutFaceLandmarkBinSize[i] = numPoints;

                        PXCMFaceData.LandmarkPoint[] landmarkPoints = new PXCMFaceData.LandmarkPoint[numPoints];
                        int prevSliceCount = FOutFaceLandmarkPoints.SliceCount;
                        FOutFaceLandmarkPoints.SliceCount = prevSliceCount + numPoints;

                        if (landmarks.QueryPoints(out landmarkPoints))
                        {
                            for (int j = 0; j < numPoints; j++)
                            {
                                int index = prevSliceCount + j;
                                FOutFaceLandmarkPoints[index] = new Vector2D(landmarkPoints[j].image.x, landmarkPoints[j].image.y);
                            }
                        }
                    }
                    else
                    {
                        FOutFaceLandmarkBinSize[i]        = 0;
                        FOutFaceLandmarkPoints.SliceCount = 0;
                    }

                    PXCMFaceData.ExpressionsData expressionData = face.QueryExpressions();
                    if (expressionData != null)
                    {
                        for (int j = 0; j < FInExpressions.SliceCount; j++)
                        {
                            PXCMFaceData.ExpressionsData.FaceExpressionResult expressionResult;
                            if (expressionData.QueryExpression(FInExpressions[j], out expressionResult))
                            {
                                FOutFaceExpressionsResult.SliceCount++;
                                FOutFaceExpressionsResult[j] = expressionResult.intensity;
                            }
                            else
                            {
                                // do nothing
                            }
                        }
                    }
                    else
                    {
                        FOutFaceExpressionsResult.SliceCount = 0;
                    }

                    PXCMFaceData.PulseData pulseData = face.QueryPulse();
                    if (pulseData != null)
                    {
                        FOutPulse.SliceCount = sliceCount;
                        FOutPulse[i]         = pulseData.QueryHeartRate();
                    }
                }
            }
        }