public AzureApiHandler(ApiKeyStore apiKeys, string region, string config, string personGroupId, DataSet dataSet) { ApiName = "Azure"; ApiKeys = apiKeys; Region = region; Client = new FaceServiceClient(ApiKeys.GetCurrentKey(), Region); DataSet = dataSet; PersonGroupId = personGroupId; TargetFaceList = new List <Face>(); SourceFaceList = new List <Face>(); SourceMatchList = new List <IdentifyResult>(); TimingResults = new List <TimingModel>(); }
public AmazonApiHandler(ApiKeyStore accessKeys, ApiKeyStore secretKeys, DataSet dataSet, string collectionName) { ApiName = "Amazon Rekognition"; AccessKeys = accessKeys; SecretKeys = secretKeys; CollectionName = collectionName; Credentials = new BasicAWSCredentials(AccessKeys.GetCurrentKey(), SecretKeys.GetCurrentKey()); Client = new AmazonRekognitionClient(Credentials, new AmazonRekognitionConfig { RegionEndpoint = RegionEndpoint.USWest2 }); DataSet = dataSet; IndexedFaces = new List <IndexFacesResponse>(); MatchResults = new List <SearchFacesByImageResponse>(); TimingResults = new List <TimingModel>(); }
private async Task AddTarget(KeyValuePair <string, Image> entry) { Guid personId = new Guid(); Face personFace = null; var addRetryPolicy = Policy.Handle <FaceAPIException>().WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(16), (ex, timeSpan) => { Console.WriteLine("API key {0} failed. Changing key.", ApiKeys.GetCurrentKey()); ApiKeys.NextKey(); Client = new FaceServiceClient(ApiKeys.GetCurrentKey(), Region); Console.WriteLine("Now using API key {0}.", ApiKeys.GetCurrentKey()); }); personId = await addRetryPolicy.ExecuteAsync(async() => await AddPerson(entry.Key)); if (personId == new Guid()) { Console.WriteLine("Failed to create person {0}.", entry.Key); return; } var findRetryPolicy = Policy.Handle <FaceAPIException>().WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(16), (ex, timeSpan) => { Console.WriteLine("API key {0} failed. Changing key.", ApiKeys.GetCurrentKey()); ApiKeys.NextKey(); Client = new FaceServiceClient(ApiKeys.GetCurrentKey(), Region); Console.WriteLine("Now using API key {0}.", ApiKeys.GetCurrentKey()); }); personFace = await findRetryPolicy.ExecuteAsync(async() => await FindFace(entry.Key)); if (personFace == null) { Console.WriteLine("Failed to find face in image."); return; } var addFaceRetryPolicy = Policy.Handle <FaceAPIException>().WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(16), (ex, timeSpan) => { Console.WriteLine("API key {0} failed. Changing key.", ApiKeys.GetCurrentKey()); ApiKeys.NextKey(); Client = new FaceServiceClient(ApiKeys.GetCurrentKey(), Region); Console.WriteLine("Now using API key {0}.", ApiKeys.GetCurrentKey()); }); await addFaceRetryPolicy.ExecuteAsync(async() => await AddFaceToPerson(entry.Key, personId, personFace)); var trainRetryPolicy = Policy.Handle <FaceAPIException>().WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(16), (ex, timeSpan) => { Console.WriteLine("API key {0} failed. Changing key.", ApiKeys.GetCurrentKey()); ApiKeys.NextKey(); Client = new FaceServiceClient(ApiKeys.GetCurrentKey(), Region); Console.WriteLine("Now using API key {0}.", ApiKeys.GetCurrentKey()); }); await trainRetryPolicy.ExecuteAsync(async() => await TrainPersonGroup()); }