コード例 #1
0
 private static PointF[] convertLandmarkFormation(
     ref FaceLandmarks _landmarks,
     ref FaceRectangle _rectangle)
 {
     PointF[] retLandmarks = new PointF[27] {
         convertPointFormation(_landmarks.EyebrowLeftOuter, _rectangle),
         convertPointFormation(_landmarks.EyebrowLeftInner, _rectangle),
         convertPointFormation(_landmarks.EyebrowRightOuter, _rectangle),
         convertPointFormation(_landmarks.EyebrowRightInner, _rectangle),
         convertPointFormation(_landmarks.EyeLeftOuter, _rectangle),
         convertPointFormation(_landmarks.EyeLeftTop, _rectangle),
         convertPointFormation(_landmarks.EyeLeftInner, _rectangle),
         convertPointFormation(_landmarks.EyeLeftBottom, _rectangle),
         convertPointFormation(_landmarks.PupilLeft, _rectangle),
         convertPointFormation(_landmarks.EyeRightOuter, _rectangle),
         convertPointFormation(_landmarks.EyeRightTop, _rectangle),
         convertPointFormation(_landmarks.EyeRightInner, _rectangle),
         convertPointFormation(_landmarks.EyeRightBottom, _rectangle),
         convertPointFormation(_landmarks.PupilRight, _rectangle),
         convertPointFormation(_landmarks.NoseRootLeft, _rectangle),
         convertPointFormation(_landmarks.NoseLeftAlarTop, _rectangle),
         convertPointFormation(_landmarks.NoseLeftAlarOutTip, _rectangle),
         convertPointFormation(_landmarks.NoseTip, _rectangle),
         convertPointFormation(_landmarks.NoseRightAlarOutTip, _rectangle),
         convertPointFormation(_landmarks.NoseRightAlarTop, _rectangle),
         convertPointFormation(_landmarks.NoseRootRight, _rectangle),
         convertPointFormation(_landmarks.MouthLeft, _rectangle),
         convertPointFormation(_landmarks.UpperLipTop, _rectangle),
         convertPointFormation(_landmarks.MouthRight, _rectangle),
         convertPointFormation(_landmarks.UnderLipBottom, _rectangle),
         convertPointFormation(_landmarks.UpperLipBottom, _rectangle),
         convertPointFormation(_landmarks.UnderLipTop, _rectangle)
     };
     return(retLandmarks);
 }
コード例 #2
0
        private static PointF convertPointFormation(
            FeatureCoordinate _landmark,
            FaceRectangle _rectangle)
        {
            PointF retPoint = new PointF();

            retPoint.X = (float)((_landmark.X - _rectangle.Left) / _rectangle.Width);
            retPoint.Y = (float)((_landmark.Y - _rectangle.Top) / _rectangle.Height);
            return(retPoint);
        }
コード例 #3
0
        // Displays the face description when the mouse is over a face rectangle.

        private void FacePhoto_MouseMove(object sender, MouseEventArgs e)
        {
            // If the REST call has not completed, return from this method.
            if (faces == null)
            {
                return;
            }

            // Find the mouse position relative to the image.
            Point mouseXY = e.GetPosition(FacePhoto);

            ImageSource  imageSource  = FacePhoto.Source;
            BitmapSource bitmapSource = (BitmapSource)imageSource;

            // Scale adjustment between the actual size and displayed size.
            var scale = FacePhoto.ActualWidth / (bitmapSource.PixelWidth / resizeFactor);

            // Check if this mouse position is over a face rectangle.
            bool mouseOverFace = false;

            for (int i = 0; i < faces.Length; ++i)
            {
                FaceRectangle fr     = faces[i].FaceRectangle;
                double        left   = fr.Left * scale;
                double        top    = fr.Top * scale;
                double        width  = fr.Width * scale;
                double        height = fr.Height * scale;

                // Display the face description for this face if the mouse is over this face rectangle.
                if (mouseXY.X >= left && mouseXY.X <= left + width && mouseXY.Y >= top && mouseXY.Y <= top + height)
                {
                    faceDescriptionStatusBar.Text = faceDescriptions[i];
                    mouseOverFace = true;
                    break;
                }
            }

            // If the mouse is not over a face rectangle.
            if (!mouseOverFace)
            {
                faceDescriptionStatusBar.Text = "Place the mouse pointer over a face to see the face description.";
            }
        }
コード例 #4
0
        private static void runFaceAPI(
            string _filePath,
            out FaceRectangle[] _rects,
            out FaceLandmarks[] _landmarks)
        {
            string  key          = "1cdb412565ae43879ea8133525e89040";
            FaceAPI faceAPI      = new FaceAPI(key);
            var     detectResult = faceAPI.detectFaces(_filePath);

            Task.WaitAll(detectResult);
            if (detectResult.Result)
            {
                _rects     = faceAPI.getFaceRectangles();
                _landmarks = faceAPI.getFaceLandmarks();
            }
            else
            {
                _rects     = new FaceRectangle[0];
                _landmarks = new FaceLandmarks[0];
            }
        }
コード例 #5
0
        private static Rectangle convertRectangleFormation(
            FaceRectangle _rectangle, string fileName)
        {
            Rectangle rect = new Rectangle(
                _rectangle.Left,
                _rectangle.Top,
                _rectangle.Width,
                _rectangle.Height);

            Image im = Image.FromFile(fileName);

            if (rect.Width + rect.Left > im.Width)
            {
                rect.Width = im.Width - rect.Left;
            }
            if (rect.Height + rect.Top > im.Height)
            {
                rect.Height = im.Height - rect.Top;
            }

            return(rect);
        }
コード例 #6
0
        /// <summary>
        /// Adds the face to face list asynchronously.
        /// </summary>
        /// <param name="faceListId">The face list identifier.</param>
        /// <param name="imageStream">The face image stream.</param>
        /// <param name="userData">The user data.</param>
        /// <param name="targetFace">The target face.</param>
        /// <returns>
        /// Add face result.
        /// </returns>
        public async Task <AddPersistedFaceResult> AddFaceToFaceListAsync(string faceListId, Stream imageStream, string userData = null, FaceRectangle targetFace = null)
        {
            var requestUrl = string.Format("{0}/{1}/{2}/{3}?userData={4}&targetFace={5}",
                                           ServiceHost, FaceListsQuery, faceListId, PersistedFacesQuery, userData,
                                           targetFace == null ? string.Empty : string.Format("{0},{1},{2},{3}", targetFace.Left, targetFace.Top, targetFace.Width, targetFace.Height));

            return(await this.SendRequestAsync <object, AddPersistedFaceResult>(HttpMethod.Post, requestUrl, imageStream));
        }
コード例 #7
0
        /// <summary>
        /// Adds a face to a person asynchronously.
        /// </summary>
        /// <param name="personGroupId">The person group id.</param>
        /// <param name="personId">The person id.</param>
        /// <param name="imageStream">The face image stream.</param>
        /// <param name="userData">The user data.</param>
        /// <param name="targetFace">The target face.</param>
        /// <returns>
        /// Add person face result.
        /// </returns>
        public async Task <AddPersistedFaceResult> AddPersonFaceAsync(string personGroupId, Guid personId, Stream imageStream, string userData = null, FaceRectangle targetFace = null)
        {
            var requestUrl = string.Format("{0}/{1}/{2}/{3}/{4}/{5}?userData={6}&targetFace={7}",
                                           ServiceHost, PersonGroupsQuery, personGroupId, PersonsQuery, personId, PersistedFacesQuery, userData,
                                           targetFace == null ? string.Empty : string.Format("{0},{1},{2},{3}", targetFace.Left, targetFace.Top, targetFace.Width, targetFace.Height));

            return(await this.SendRequestAsync <Stream, AddPersistedFaceResult>(HttpMethod.Post, requestUrl, imageStream));
        }