Esempio n. 1
0
        async Task ExecuteFindSimilarFaces(FindSimilarMatchMode matchMode, int gridViewResourceId)
        {
            List <SimilarFaceResult> results = null;

            try
            {
                AddLog($"Request: Find {matchMode.ToString ()} similar faces to {targetFaceListAdapter.SelectedFace.Id} in {faceListAdapter.Count} face(s)");
                progressDialog.Show();
                progressDialog.SetMessage("Finding Similar Faces...");
                SetInfo("Finding Similar Faces...");

                results = await FaceClient.Shared.FindSimilar(targetFaceListAdapter.SelectedFace, faceListAdapter.Faces, 4 /*max candidates*/, matchMode);

                var resultString = $"Found {results?.Count ?? 0} {matchMode} similar face{(results?.Count != 1 ? "s" : "")}";
                AddLog("Response: Success. " + resultString);
                AppendInfo(resultString);
            }
            catch (Exception e)
            {
                AddLog(e.Message);
            }

            progressDialog.Dismiss();

            // Show the result of face finding similar faces.
            var similarFaces = FindViewById <GridView> (gridViewResourceId);

            similarFaceListAdapter = new SimilarFaceListAdapter(results, faceListAdapter);
            similarFaces.Adapter   = similarFaceListAdapter;
        }
        /// <summary>
        /// Finds the similar faces asynchronously.
        /// </summary>
        /// <param name="faceId">The face identifier.</param>
        /// <param name="faceListId">The face list identifier.</param>
        /// <param name="mode">Algorithm mode option, default as "matchPerson".</param>
        /// <param name="maxNumOfCandidatesReturned">The max number of candidates returned.</param>
        /// <returns>
        /// The similar persisted faces.
        /// </returns>
        public async Task <SimilarPersistedFace[]> FindSimilarAsync(Guid faceId, string faceListId, FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
        {
            var requestUrl = string.Format("{0}/{1}", ServiceHost, FindSimilarsQuery);

            return(await this.SendRequestAsync <object, SimilarPersistedFace[]>(
                       HttpMethod.Post,
                       requestUrl,
                       new
            {
                faceId = faceId,
                faceListId = faceListId,
                maxNumOfCandidatesReturned = maxNumOfCandidatesReturned,
                mode = mode.ToString()
            }));
        }