Exemplo n.º 1
0
        public static int FacePointsCount()
        {
            if (landmarksData == null)
            {
                return(0);
            }

            return(landmarksData.QueryNumPoints());
        }
Exemplo n.º 2
0
        private static void UpdateFaceGeometry(PXCMFaceData.LandmarksData landmarksData)
        {
            if (landmarksData == null)
            {
                return;
            }

            for (int i = 0; i < landmarksData.QueryNumPoints(); i++)
            {
                PXCMFaceData.LandmarkPoint outPoint;
                if (landmarksData.QueryPoint(i, out outPoint))
                {
                    faceGeometry[i] = new Vector(-outPoint.world.x, outPoint.world.y, -outPoint.world.z);
                }
            }
        }
Exemplo n.º 3
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();
                    }
                }
            }
        }