예제 #1
0
        /// <summary>
        /// Finds the detected face within the list of faces supplied, that is closest to the object identity's position.
        /// </summary>
        /// <param name="faces">A list of detected faces by the Windows FaceAnalysis namespace.</param>
        /// <returns>The face object that is the closest to the object identity's position.</returns>
        public DetectedFace FindNearestFace(IList <DetectedFace> faces)
        {
            if (faces.Count == 0)
            {
                return(null);
            }

            DetectedFace nearestFace         = null;
            var          nearestFaceDistance = double.MaxValue;

            foreach (var face in faces)
            {
                var faceCenter = IdentityInterpolation.GetCenterPoint(face.FaceBox);
                var distance   = IdentityInterpolation.GetRelativeDistance(centerPoint, faceCenter);
                if (distance < nearestFaceDistance)
                {
                    nearestFace         = face;
                    nearestFaceDistance = distance;
                }
            }

            return(nearestFace);
        }
예제 #2
0
 /// <summary>
 /// Updates the position of the face (probably in a new frame).
 /// Updates both the bounding box as well as the center point of the (new) bounding box.
 /// </summary>
 /// <param name="faceBox">The bounding box indicating the position and size of the face.</param>
 public void UpdatePosition(BitmapBounds faceBox)
 {
     boundingBox = faceBox;
     surfaceArea = (int)faceBox.Width * (int)faceBox.Height;
     centerPoint = IdentityInterpolation.GetCenterPoint(faceBox);
 }