Beispiel #1
0
 public FaceLandmarks()
 {
     _totalNum      = 68;
     _emptylandmark = new FaceLandmark {
         X = 0, Y = 0
     };
     _eyeDistance = 0;
     landmarkList = new List <FaceLandmark>();
 }
        /// <summary>
        /// Processes scors and boxes and generate a list of face rectangles.
        /// </summary>
        /// <param name="landmarkTensors">landmark output of Onnx model.</param>
        /// <param name="imageX">X start position of the image.</param>
        /// <param name="imageY">Y start position of the image.</param>
        /// <param name="imageWidth">width of the image.</param>
        /// <param name="imageHeight">height of the image.</param>
        public static FaceLandmarks Predict(TensorFloat landmarkTensors, int imageX, int imageY, int imageWidth, int imageHeight)
        {
            var faceLandmarks = new FaceLandmarks();

            IReadOnlyList <float> vectorLandmarks   = landmarkTensors.GetAsVectorView();
            IList <float>         landmarkFloatList = vectorLandmarks.ToList();
            long numAnchors = (long)Math.Ceiling(landmarkTensors.Shape[1] * 0.5);

            for (var i = 0; i < numAnchors; i++)
            {
                var mark = new FaceLandmark
                {
                    X = landmarkFloatList[i * 2] * imageWidth + imageX,
                    Y = landmarkFloatList[i * 2 + 1] * imageHeight + imageY
                };

                faceLandmarks.landmarkList.Add(mark);
            }

            return(faceLandmarks);
        }