/// <summary> /// Called when a face is detected. /// </summary> /// <param name="module">The module.</param> private void OnFaceCallback(PXCMFaceModule module) { PXCMRectI32 bounds; using (var faceData = module.CreateOutput()) { faceData.Update(); var faces = faceData.QueryFaces(); foreach (var face in faces) { var detection = face.QueryDetection(); detection.QueryBoundingRect(out bounds); // Debug.WriteLine("{0} Face detected: {1}", Time(), bounds); var landmarkData = face.QueryLandmarks(); if (landmarkData != null) { PXCMFaceData.LandmarkPoint[] landmarks; landmarkData.QueryPoints(out landmarks); var landmarkDict = new Dictionary<string, Point>(); foreach(PXCMFaceData.LandmarkPoint landmark in landmarks) { landmarkDict.Add("LANDMARK_" + landmark.source.index, new Point(landmark.image.x, landmark.image.y)); /*Debug.WriteLine("{0}/{1} at {2},{3},{4}", landmark.source.index, landmark.source.alias, landmark.image.x, landmark.image.y, landmark.confidenceImage); */ } var landmarkArgs = new LandmarksEventArgs(landmarkDict, Resolution.Item1.width, Resolution.Item1.height); OnLandmarksFound(this, landmarkArgs); } // Expression var expressionValues = new Dictionary<string, double>(); var expressionData = face.QueryExpressions(); if (expressionData != null) { foreach (PXCMFaceData.ExpressionsData.FaceExpression expression in Enum.GetValues(typeof(PXCMFaceData.ExpressionsData.FaceExpression))) { PXCMFaceData.ExpressionsData.FaceExpressionResult score; expressionData.QueryExpression(expression, out score); expressionValues.Add(expression.ToString(), score.intensity / 100d); // Debug.WriteLine("{0} Expression: {1} == {2}", Time(), expression, score.intensity / 100d); } } OnFaceFound(this, new FaceEventArgs(new Rectangle(bounds.x, bounds.y, bounds.w, bounds.h), expressionValues, Resolution.Item1.width, Resolution.Item1.height)); OnDataAvailable(this, new DataEventArgs(expressionValues)); } } }
/// <summary> /// Handles the <see cref="E:LandmarksFound" /> event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="LandmarksEventArgs"/> instance containing the event data.</param> private void OnLandmarksFound(object sender, LandmarksEventArgs e) { if (LandmarksFound != null) LandmarksFound(sender, e); }