Пример #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;
        }
Пример #2
0
        public virtual SimilarFace[] FindSimilar(Guid faceId, Guid[] faceIds, FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
        {
            var response = RepositoryClient.SendJsonPost(ApiKeys.Face, $"{ApiKeys.FaceEndpoint}findsimilars", JsonConvert.SerializeObject(new FaceSimilarityRequest {
                FaceId = faceId, FaceIds = faceIds, MaxNumOfCandidatesReturned = 20, Mode = mode
            }));

            return(JsonConvert.DeserializeObject <SimilarFace[]>(response));
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the FindSimilarRequest class.
 /// </summary>
 /// <param name="faceId">FaceId of the query face. User needs to call
 /// Face - Detect first to get a valid faceId. Note that this faceId is
 /// not persisted and will expire 24 hours after the detection
 /// call</param>
 /// <param name="faceListId">An existing user-specified unique
 /// candidate face list, created in Face List - Create a Face List.
 /// Face list contains a set of persistedFaceIds which are persisted
 /// and will never expire. Parameter faceListId, largeFaceListId and
 /// faceIds should not be provided at the same time.</param>
 /// <param name="largeFaceListId">An existing user-specified unique
 /// candidate large face list, created in LargeFaceList - Create. Large
 /// face list contains a set of persistedFaceIds which are persisted
 /// and will never expire. Parameter faceListId, largeFaceListId and
 /// faceIds should not be provided at the same time.</param>
 /// <param name="faceIds">An array of candidate faceIds. All of them
 /// are created by Face - Detect and the faceIds will expire 24 hours
 /// after the detection call. The number of faceIds is limited to 1000.
 /// Parameter faceListId, largeFaceListId and faceIds should not be
 /// provided at the same time.</param>
 /// <param name="maxNumOfCandidatesReturned">The number of top similar
 /// faces returned. The valid range is [1, 1000].</param>
 /// <param name="mode">Similar face searching mode. It can be
 /// "matchPerson" or "matchFace". Possible values include:
 /// 'matchPerson', 'matchFace'</param>
 public FindSimilarRequest(System.Guid faceId, string faceListId = default(string), string largeFaceListId = default(string), IList <System.Guid?> faceIds = default(IList <System.Guid?>), int?maxNumOfCandidatesReturned = default(int?), FindSimilarMatchMode mode = default(FindSimilarMatchMode))
 {
     FaceId                     = faceId;
     FaceListId                 = faceListId;
     LargeFaceListId            = largeFaceListId;
     FaceIds                    = faceIds;
     MaxNumOfCandidatesReturned = maxNumOfCandidatesReturned;
     Mode = mode;
     CustomInit();
 }
        internal static string ToSerializedValue(this FindSimilarMatchMode value)
        {
            switch (value)
            {
            case FindSimilarMatchMode.MatchPerson:
                return("matchPerson");

            case FindSimilarMatchMode.MatchFace:
                return("matchFace");
            }
            return(null);
        }
 public virtual SimilarFace[] FindSimilar(Guid faceId, Guid[] faceIds, FindSimilarMatchMode mode,
                                          int maxNumOfCandidatesReturned = 20)
 {
     return(PolicyService.ExecuteRetryAndCapture400Errors(
                "FaceService.FindSimilar",
                ApiKeys.FaceRetryInSeconds,
                () =>
     {
         var result = FaceRepository.FindSimilar(faceId, faceIds, mode, maxNumOfCandidatesReturned);
         return result;
     },
                null));
 }
 public virtual Task <SimilarPersistedFace[]> FindSimilarAsync(Guid faceId, string faceListId,
                                                               FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
 {
     return(PolicyService.ExecuteRetryAndCapture400Errors(
                "FaceService.FindSimilarAsync",
                ApiKeys.FaceRetryInSeconds,
                () =>
     {
         var result = FaceRepository.FindSimilarAsync(faceId, faceListId, mode, maxNumOfCandidatesReturned);
         return result;
     },
                null));
 }
Пример #7
0
 public Task <SimilarPersistedFace[]> FindSimilarAsync(Guid faceId, string faceListId, FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
 {
     throw new NotImplementedException();
 }
Пример #8
0
 public Task <SimilarFace[]> FindSimilarAsync(Guid faceId, Guid[] faceIds, FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
 {
     throw new NotImplementedException();
 }
 public static async Task <IList <SimilarFace> > FindSimilarAsync(Guid faceId, string faceListId, string largeFaceListId, FindSimilarMatchMode matchMode, int maxNumOfCandidatesReturned = 1)
 {
     return(await RunTaskWithAutoRetryOnQuotaLimitExceededError(() => Client.Face.FindSimilarAsync(faceId, faceListId, largeFaceListId, mode: matchMode, maxNumOfCandidatesReturned: maxNumOfCandidatesReturned)));
 }
Пример #10
0
 /// <summary>
 /// Given query face's faceId, find the similar-looking faces from a faceId
 /// array, a face list or a large face list.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='faceId'>
 /// FaceId of the query face. User needs to call Face - Detect first to get a
 /// valid faceId. Note that this faceId is not persisted and will expire 24
 /// hours after the detection call
 /// </param>
 /// <param name='faceListId'>
 /// An existing user-specified unique candidate face list, created in Face List
 /// - Create a Face List. Face list contains a set of persistedFaceIds which
 /// are persisted and will never expire. Parameter faceListId, largeFaceListId
 /// and faceIds should not be provided at the same time。
 /// </param>
 /// <param name='largeFaceListId'>
 /// An existing user-specified unique candidate large face list, created in
 /// LargeFaceList - Create. Large face list contains a set of persistedFaceIds
 /// which are persisted and will never expire. Parameter faceListId,
 /// largeFaceListId and faceIds should not be provided at the same time.
 /// </param>
 /// <param name='faceIds'>
 /// An array of candidate faceIds. All of them are created by Face - Detect and
 /// the faceIds will expire 24 hours after the detection call. The number of
 /// faceIds is limited to 1000. Parameter faceListId, largeFaceListId and
 /// faceIds should not be provided at the same time.
 /// </param>
 /// <param name='maxNumOfCandidatesReturned'>
 /// The number of top similar faces returned. The valid range is [1, 1000].
 /// </param>
 /// <param name='mode'>
 /// Similar face searching mode. It can be "matchPerson" or "matchFace".
 /// Possible values include: 'matchPerson', 'matchFace'
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <IList <SimilarFace> > FindSimilarAsync(this IFaceOperations operations, System.Guid faceId, string faceListId = default(string), string largeFaceListId = default(string), IList <System.Guid?> faceIds = default(IList <System.Guid?>), int?maxNumOfCandidatesReturned = 20, FindSimilarMatchMode mode = default(FindSimilarMatchMode), CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.FindSimilarWithHttpMessagesAsync(faceId, faceListId, largeFaceListId, faceIds, maxNumOfCandidatesReturned, mode, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #11
0
        /// <summary>
        /// Finds faces similar to <c>targetFace</c> in the given <c>faceList</c>.
        /// </summary>
        /// <returns>A list of <see cref="SimilarFaceResult"/> indicating similar face(s) and associated confidence factor.</returns>
        /// <param name="targetFace">The target <see cref="Face"/> to find similar faces to.</param>
        /// <param name="faceList">The face list containing faces to compare to <c>targetFace</c>.</param>
        /// <param name="maxCandidatesReturned">The maximum number of candidate faces to return.</param>
        /// <param name="matchMode">The <see cref="FindSimilarMatchMode"/> to use when comparing - matchFace or matchPerson (default).</param>
        /// <remarks><c>maxCandidatesReturned</c> and <c>matchMode</c> are not currently respsected on iOS due to native SDK limiations.</remarks>
        public async Task <List <SimilarFaceResult> > FindSimilar(Model.Face targetFace, List <Model.Face> faceList, int maxCandidatesReturned = 1, FindSimilarMatchMode matchMode = FindSimilarMatchMode.MatchPerson)
        {
            try
            {
                var faceIdList = faceList.Select(f => f.Id).ToArray();

                var results = await FindSimilar(targetFace.Id, faceIdList, maxCandidatesReturned, matchMode);

                foreach (var similarFaceResult in results)
                {
                    similarFaceResult.Face = faceList.FirstOrDefault(f => f.Id == similarFaceResult.FaceId);
                }

                return(results);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                throw;
            }
        }
Пример #12
0
        public virtual async Task <SimilarPersistedFace[]> FindSimilarAsync(Guid faceId, string faceListId, FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
        {
            var response = await RepositoryClient.SendJsonPostAsync(ApiKeys.Face, $"{ApiKeys.FaceEndpoint}findsimilars", JsonConvert.SerializeObject(new FaceSimilarityRequest {
                FaceId = faceId, FaceListId = faceListId, MaxNumOfCandidatesReturned = 20, Mode = mode
            }));

            return(JsonConvert.DeserializeObject <SimilarPersistedFace[]>(response));
        }
        /// <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()
            }));
        }
Пример #14
0
 public Task <SimilarPersistedFace[]> FindSimilarAsync(Guid faceId, string faceListId, FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
 {
     return(innerClient.FindSimilarAsync(faceId, faceListId, mode, maxNumOfCandidatesReturned));
 }
Пример #15
0
 public Task <SimilarFace[]> FindSimilarAsync(Guid faceId, Guid[] faceIds, FindSimilarMatchMode mode, int maxNumOfCandidatesReturned = 20)
 {
     return(innerClient.FindSimilarAsync(faceId, faceIds, mode, maxNumOfCandidatesReturned));
 }
Пример #16
0
        /// <summary>
        /// Finds faces similar to a target face in the given list of face Ids.
        /// </summary>
        /// <returns>A list of <see cref="SimilarFaceResult"/> indicating similar face(s) and associated confidence factor.</returns>
        /// <param name="targetFaceId">The Id of the target <see cref="Face"/> to find similar faces to.</param>
        /// <param name="faceIds">The face list containing face Ids to compare to the target Face.</param>
        /// <param name="maxCandidatesReturned">The maximum number of candidate faces to return.</param>
        /// <param name="matchMode">The <see cref="FindSimilarMatchMode"/> to use when comparing - matchFace or matchPerson (default).</param>
        /// <remarks><c>maxCandidatesReturned</c> and <c>matchMode</c> are not currently respsected on iOS due to native SDK limiations.</remarks>
        public Task <List <SimilarFaceResult> > FindSimilar(string targetFaceId, string [] faceIds, int maxCandidatesReturned = 1, FindSimilarMatchMode matchMode = FindSimilarMatchMode.MatchPerson)
        {
            var tcs = new TaskCompletionSource <List <SimilarFaceResult> > ();

            var results = new List <SimilarFaceResult> ();

            Client.FindSimilarWithFaceId(
                targetFaceId,
                faceIds,
                (similarFaces, error) => AdaptListResultCallback(error, tcs, similarFaces, MappingExtensions.ToSimilarFaceResult))
            .Resume();

            return(tcs.Task);
        }
Пример #17
0
 /// <summary>
 /// Finds faces similar to a target face in the given list of face Ids.
 /// </summary>
 /// <returns>A list of <see cref="SimilarFaceResult"/> indicating similar face(s) and associated confidence factor.</returns>
 /// <param name="targetFaceId">The Id of the target <see cref="Face"/> to find similar faces to.</param>
 /// <param name="faceIds">The face list containing face Ids to compare to the target Face.</param>
 /// <param name="maxCandidatesReturned">The maximum number of candidate faces to return.</param>
 /// <param name="matchMode">The <see cref="FindSimilarMatchMode"/> to use when comparing - matchFace or matchPerson (default).</param>
 public Task <List <SimilarFaceResult> > FindSimilar(string targetFaceId, string [] faceIds, int maxCandidatesReturned = 1, FindSimilarMatchMode matchMode = FindSimilarMatchMode.MatchPerson)
 {
     return(AdaptListResultAction(() => Client.FindSimilar(targetFaceId.ToUUID(), faceIds.AsUUIDs(), maxCandidatesReturned, matchMode.AsJavaEnum <FaceServiceClientFindSimilarMatchMode> ()), MappingExtensions.ToSimilarFaceResult));
 }
Пример #18
0
        /// <summary>
        /// Busca si existen rostros actualmente registrados.
        /// </summary>
        /// <param name="faceId"></param>
        /// <param name="facesIds"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        private async Task <Coincidence> FindSimilarFaceAsync(Guid faceId, Guid[] facesIds, FindSimilarMatchMode mode)
        {
            try
            {
                SimilarFace[] similarFaces = await _faceClient.FindSimilarAsync(faceId, facesIds, mode);

                SimilarFace similarFace = similarFaces.ToList().Where(x => x.Confidence > 0.30).FirstOrDefault();
                return(new Entities.Coincidence
                {
                    MatchId = (similarFace != null) ? similarFace.FaceId : Guid.Empty,
                    Confidence = (similarFace != null) ? similarFace.Confidence : 0,
                    NewId = faceId
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }