com.microsoft.azure.cognitiveservices.vision.faceapi.implementation.FacesImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-cognitiveservices-faceapi Show documentation
Show all versions of azure-cognitiveservices-faceapi Show documentation
This package contains Microsoft Cognitive Service Face API SDK.
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
*/
package com.microsoft.azure.cognitiveservices.vision.faceapi.implementation;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.FindSimilarOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.IdentifyOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.DetectWithUrlOptionalParameter;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.DetectWithStreamOptionalParameter;
import retrofit2.Retrofit;
import com.microsoft.azure.cognitiveservices.vision.faceapi.Faces;
import com.google.common.base.Joiner;
import com.google.common.reflect.TypeToken;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.APIErrorException;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.DetectedFace;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.FaceAttributeType;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.FindSimilarMatchMode;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.FindSimilarRequest;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.GroupRequest;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.GroupResult;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.IdentifyRequest;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.IdentifyResult;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.ImageUrl;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.SimilarFace;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.VerifyFaceToFaceRequest;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.VerifyFaceToPersonRequest;
import com.microsoft.azure.cognitiveservices.vision.faceapi.models.VerifyResult;
import com.microsoft.rest.CollectionFormat;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import com.microsoft.rest.Validator;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.Response;
import rx.functions.Func1;
import rx.Observable;
/**
* An instance of this class provides access to all the operations defined
* in Faces.
*/
public class FacesImpl implements Faces {
/** The Retrofit service to perform REST calls. */
private FacesService service;
/** The service client containing this operation class. */
private FaceAPIImpl client;
/**
* Initializes an instance of FacesImpl.
*
* @param retrofit the Retrofit instance built from a Retrofit Builder.
* @param client the instance of the service client containing this operation class.
*/
public FacesImpl(Retrofit retrofit, FaceAPIImpl client) {
this.service = retrofit.create(FacesService.class);
this.client = client;
}
/**
* The interface defining all the services for Faces to be
* used by Retrofit to perform actually REST calls.
*/
interface FacesService {
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.Faces findSimilar" })
@POST("findsimilars")
Observable> findSimilar(@Header("accept-language") String acceptLanguage, @Body FindSimilarRequest body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.Faces group" })
@POST("group")
Observable> group(@Header("accept-language") String acceptLanguage, @Body GroupRequest body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.Faces identify" })
@POST("identify")
Observable> identify(@Header("accept-language") String acceptLanguage, @Body IdentifyRequest body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.Faces verifyFaceToFace" })
@POST("verify")
Observable> verifyFaceToFace(@Header("accept-language") String acceptLanguage, @Body VerifyFaceToFaceRequest body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.Faces detectWithUrl" })
@POST("detect")
Observable> detectWithUrl(@Query("returnFaceId") Boolean returnFaceId, @Query("returnFaceLandmarks") Boolean returnFaceLandmarks, @Query("returnFaceAttributes") String returnFaceAttributes, @Header("accept-language") String acceptLanguage, @Body ImageUrl imageUrl, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.Faces verifyFaceToPerson" })
@POST("verify")
Observable> verifyFaceToPerson(@Header("accept-language") String acceptLanguage, @Body VerifyFaceToPersonRequest body, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
@Headers({ "Content-Type: application/octet-stream", "x-ms-logging-context: com.microsoft.azure.cognitiveservices.vision.faceapi.Faces detectWithStream" })
@POST("detect")
Observable> detectWithStream(@Query("returnFaceId") Boolean returnFaceId, @Query("returnFaceLandmarks") Boolean returnFaceLandmarks, @Query("returnFaceAttributes") String returnFaceAttributes, @Body RequestBody image, @Header("accept-language") String acceptLanguage, @Header("x-ms-parameterized-host") String parameterizedHost, @Header("User-Agent") String userAgent);
}
/**
* Given query face's faceId, find the similar-looking faces from a faceId array or a faceListId.
*
* @param 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 findSimilarOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the List<SimilarFace> object if successful.
*/
public List findSimilar(UUID faceId, FindSimilarOptionalParameter findSimilarOptionalParameter) {
return findSimilarWithServiceResponseAsync(faceId, findSimilarOptionalParameter).toBlocking().single().body();
}
/**
* Given query face's faceId, find the similar-looking faces from a faceId array or a faceListId.
*
* @param 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 findSimilarOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture> findSimilarAsync(UUID faceId, FindSimilarOptionalParameter findSimilarOptionalParameter, final ServiceCallback> serviceCallback) {
return ServiceFuture.fromResponse(findSimilarWithServiceResponseAsync(faceId, findSimilarOptionalParameter), serviceCallback);
}
/**
* Given query face's faceId, find the similar-looking faces from a faceId array or a faceListId.
*
* @param 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 findSimilarOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<SimilarFace> object
*/
public Observable> findSimilarAsync(UUID faceId, FindSimilarOptionalParameter findSimilarOptionalParameter) {
return findSimilarWithServiceResponseAsync(faceId, findSimilarOptionalParameter).map(new Func1>, List>() {
@Override
public List call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Given query face's faceId, find the similar-looking faces from a faceId array or a faceListId.
*
* @param 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 findSimilarOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<SimilarFace> object
*/
public Observable>> findSimilarWithServiceResponseAsync(UUID faceId, FindSimilarOptionalParameter findSimilarOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (faceId == null) {
throw new IllegalArgumentException("Parameter faceId is required and cannot be null.");
}
final String faceListId = findSimilarOptionalParameter != null ? findSimilarOptionalParameter.faceListId() : null;
final List faceIds = findSimilarOptionalParameter != null ? findSimilarOptionalParameter.faceIds() : null;
final Integer maxNumOfCandidatesReturned = findSimilarOptionalParameter != null ? findSimilarOptionalParameter.maxNumOfCandidatesReturned() : null;
final FindSimilarMatchMode mode = findSimilarOptionalParameter != null ? findSimilarOptionalParameter.mode() : null;
FindSimilarRequest body = new FindSimilarRequest();
body.withFaceId(faceId);
body.withFaceListId(null);
body.withFaceIds(null);
body.withMaxNumOfCandidatesReturned(null);
body.withMode(null);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return findSimilarWithServiceResponseAsync(faceId, faceListId, faceIds, maxNumOfCandidatesReturned, mode);
}
/**
* Given query face's faceId, find the similar-looking faces from a faceId array or a faceListId.
*
* @param 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 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 and faceIds should not be provided at the same time
* @param 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.
* @param maxNumOfCandidatesReturned The number of top similar faces returned. The valid range is [1, 1000].
* @param mode Similar face searching mode. It can be "matchPerson" or "matchFace". Possible values include: 'matchPerson', 'matchFace'
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<SimilarFace> object
*/
public Observable>> findSimilarWithServiceResponseAsync(UUID faceId, String faceListId, List faceIds, Integer maxNumOfCandidatesReturned, FindSimilarMatchMode mode) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (faceId == null) {
throw new IllegalArgumentException("Parameter faceId is required and cannot be null.");
}
Validator.validate(faceIds);
FindSimilarRequest body = new FindSimilarRequest();
body.withFaceId(faceId);
body.withFaceListId(faceListId);
body.withFaceIds(faceIds);
body.withMaxNumOfCandidatesReturned(maxNumOfCandidatesReturned);
body.withMode(mode);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.findSimilar(this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> clientResponse = findSimilarDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> findSimilarDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., APIErrorException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Divide candidate faces into groups based on face similarity.
*
* @param faceIds Array of candidate faceId created by Face - Detect. The maximum is 1000 faces
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the GroupResult object if successful.
*/
public GroupResult group(List faceIds) {
return groupWithServiceResponseAsync(faceIds).toBlocking().single().body();
}
/**
* Divide candidate faces into groups based on face similarity.
*
* @param faceIds Array of candidate faceId created by Face - Detect. The maximum is 1000 faces
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture groupAsync(List faceIds, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(groupWithServiceResponseAsync(faceIds), serviceCallback);
}
/**
* Divide candidate faces into groups based on face similarity.
*
* @param faceIds Array of candidate faceId created by Face - Detect. The maximum is 1000 faces
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the GroupResult object
*/
public Observable groupAsync(List faceIds) {
return groupWithServiceResponseAsync(faceIds).map(new Func1, GroupResult>() {
@Override
public GroupResult call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Divide candidate faces into groups based on face similarity.
*
* @param faceIds Array of candidate faceId created by Face - Detect. The maximum is 1000 faces
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the GroupResult object
*/
public Observable> groupWithServiceResponseAsync(List faceIds) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (faceIds == null) {
throw new IllegalArgumentException("Parameter faceIds is required and cannot be null.");
}
Validator.validate(faceIds);
GroupRequest body = new GroupRequest();
body.withFaceIds(faceIds);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.group(this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = groupDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse groupDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Identify unknown faces from a person group.
*
* @param personGroupId PersonGroupId of the target person group, created by PersonGroups.Create
* @param faceIds Array of query faces faceIds, created by the Face - Detect. Each of the faces are identified independently. The valid number of faceIds is between [1, 10].
* @param identifyOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the List<IdentifyResult> object if successful.
*/
public List identify(String personGroupId, List faceIds, IdentifyOptionalParameter identifyOptionalParameter) {
return identifyWithServiceResponseAsync(personGroupId, faceIds, identifyOptionalParameter).toBlocking().single().body();
}
/**
* Identify unknown faces from a person group.
*
* @param personGroupId PersonGroupId of the target person group, created by PersonGroups.Create
* @param faceIds Array of query faces faceIds, created by the Face - Detect. Each of the faces are identified independently. The valid number of faceIds is between [1, 10].
* @param identifyOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture> identifyAsync(String personGroupId, List faceIds, IdentifyOptionalParameter identifyOptionalParameter, final ServiceCallback> serviceCallback) {
return ServiceFuture.fromResponse(identifyWithServiceResponseAsync(personGroupId, faceIds, identifyOptionalParameter), serviceCallback);
}
/**
* Identify unknown faces from a person group.
*
* @param personGroupId PersonGroupId of the target person group, created by PersonGroups.Create
* @param faceIds Array of query faces faceIds, created by the Face - Detect. Each of the faces are identified independently. The valid number of faceIds is between [1, 10].
* @param identifyOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<IdentifyResult> object
*/
public Observable> identifyAsync(String personGroupId, List faceIds, IdentifyOptionalParameter identifyOptionalParameter) {
return identifyWithServiceResponseAsync(personGroupId, faceIds, identifyOptionalParameter).map(new Func1>, List>() {
@Override
public List call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Identify unknown faces from a person group.
*
* @param personGroupId PersonGroupId of the target person group, created by PersonGroups.Create
* @param faceIds Array of query faces faceIds, created by the Face - Detect. Each of the faces are identified independently. The valid number of faceIds is between [1, 10].
* @param identifyOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<IdentifyResult> object
*/
public Observable>> identifyWithServiceResponseAsync(String personGroupId, List faceIds, IdentifyOptionalParameter identifyOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (faceIds == null) {
throw new IllegalArgumentException("Parameter faceIds is required and cannot be null.");
}
Validator.validate(faceIds);
final Integer maxNumOfCandidatesReturned = identifyOptionalParameter != null ? identifyOptionalParameter.maxNumOfCandidatesReturned() : null;
final Double confidenceThreshold = identifyOptionalParameter != null ? identifyOptionalParameter.confidenceThreshold() : null;
IdentifyRequest body = new IdentifyRequest();
body.withPersonGroupId(personGroupId);
body.withFaceIds(faceIds);
body.withMaxNumOfCandidatesReturned(null);
body.withConfidenceThreshold(null);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return identifyWithServiceResponseAsync(personGroupId, faceIds, maxNumOfCandidatesReturned, confidenceThreshold);
}
/**
* Identify unknown faces from a person group.
*
* @param personGroupId PersonGroupId of the target person group, created by PersonGroups.Create
* @param faceIds Array of query faces faceIds, created by the Face - Detect. Each of the faces are identified independently. The valid number of faceIds is between [1, 10].
* @param maxNumOfCandidatesReturned The range of maxNumOfCandidatesReturned is between 1 and 5 (default is 1).
* @param confidenceThreshold Confidence threshold of identification, used to judge whether one face belong to one person. The range of confidenceThreshold is [0, 1] (default specified by algorithm).
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<IdentifyResult> object
*/
public Observable>> identifyWithServiceResponseAsync(String personGroupId, List faceIds, Integer maxNumOfCandidatesReturned, Double confidenceThreshold) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (faceIds == null) {
throw new IllegalArgumentException("Parameter faceIds is required and cannot be null.");
}
Validator.validate(faceIds);
IdentifyRequest body = new IdentifyRequest();
body.withPersonGroupId(personGroupId);
body.withFaceIds(faceIds);
body.withMaxNumOfCandidatesReturned(maxNumOfCandidatesReturned);
body.withConfidenceThreshold(confidenceThreshold);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.identify(this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> clientResponse = identifyDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> identifyDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., APIErrorException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Verify whether two faces belong to a same person or whether one face belongs to a person.
*
* @param faceId1 FaceId of the first face, comes from Face - Detect
* @param faceId2 FaceId of the second face, comes from Face - Detect
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the VerifyResult object if successful.
*/
public VerifyResult verifyFaceToFace(UUID faceId1, UUID faceId2) {
return verifyFaceToFaceWithServiceResponseAsync(faceId1, faceId2).toBlocking().single().body();
}
/**
* Verify whether two faces belong to a same person or whether one face belongs to a person.
*
* @param faceId1 FaceId of the first face, comes from Face - Detect
* @param faceId2 FaceId of the second face, comes from Face - Detect
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture verifyFaceToFaceAsync(UUID faceId1, UUID faceId2, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(verifyFaceToFaceWithServiceResponseAsync(faceId1, faceId2), serviceCallback);
}
/**
* Verify whether two faces belong to a same person or whether one face belongs to a person.
*
* @param faceId1 FaceId of the first face, comes from Face - Detect
* @param faceId2 FaceId of the second face, comes from Face - Detect
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the VerifyResult object
*/
public Observable verifyFaceToFaceAsync(UUID faceId1, UUID faceId2) {
return verifyFaceToFaceWithServiceResponseAsync(faceId1, faceId2).map(new Func1, VerifyResult>() {
@Override
public VerifyResult call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Verify whether two faces belong to a same person or whether one face belongs to a person.
*
* @param faceId1 FaceId of the first face, comes from Face - Detect
* @param faceId2 FaceId of the second face, comes from Face - Detect
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the VerifyResult object
*/
public Observable> verifyFaceToFaceWithServiceResponseAsync(UUID faceId1, UUID faceId2) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (faceId1 == null) {
throw new IllegalArgumentException("Parameter faceId1 is required and cannot be null.");
}
if (faceId2 == null) {
throw new IllegalArgumentException("Parameter faceId2 is required and cannot be null.");
}
VerifyFaceToFaceRequest body = new VerifyFaceToFaceRequest();
body.withFaceId1(faceId1);
body.withFaceId2(faceId2);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.verifyFaceToFace(this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = verifyFaceToFaceDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse verifyFaceToFaceDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param url the String value
* @param detectWithUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the List<DetectedFace> object if successful.
*/
public List detectWithUrl(String url, DetectWithUrlOptionalParameter detectWithUrlOptionalParameter) {
return detectWithUrlWithServiceResponseAsync(url, detectWithUrlOptionalParameter).toBlocking().single().body();
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param url the String value
* @param detectWithUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture> detectWithUrlAsync(String url, DetectWithUrlOptionalParameter detectWithUrlOptionalParameter, final ServiceCallback> serviceCallback) {
return ServiceFuture.fromResponse(detectWithUrlWithServiceResponseAsync(url, detectWithUrlOptionalParameter), serviceCallback);
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param url the String value
* @param detectWithUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<DetectedFace> object
*/
public Observable> detectWithUrlAsync(String url, DetectWithUrlOptionalParameter detectWithUrlOptionalParameter) {
return detectWithUrlWithServiceResponseAsync(url, detectWithUrlOptionalParameter).map(new Func1>, List>() {
@Override
public List call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param url the String value
* @param detectWithUrlOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<DetectedFace> object
*/
public Observable>> detectWithUrlWithServiceResponseAsync(String url, DetectWithUrlOptionalParameter detectWithUrlOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (url == null) {
throw new IllegalArgumentException("Parameter url is required and cannot be null.");
}
final Boolean returnFaceId = detectWithUrlOptionalParameter != null ? detectWithUrlOptionalParameter.returnFaceId() : null;
final Boolean returnFaceLandmarks = detectWithUrlOptionalParameter != null ? detectWithUrlOptionalParameter.returnFaceLandmarks() : null;
final List returnFaceAttributes = detectWithUrlOptionalParameter != null ? detectWithUrlOptionalParameter.returnFaceAttributes() : null;
ImageUrl imageUrl = new ImageUrl();
imageUrl.withUrl(url);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String returnFaceAttributesConverted = this.client.serializerAdapter().serializeList(returnFaceAttributes, CollectionFormat.CSV);
return detectWithUrlWithServiceResponseAsync(url, returnFaceId, returnFaceLandmarks, returnFaceAttributes);
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param url the String value
* @param returnFaceId A value indicating whether the operation should return faceIds of detected faces.
* @param returnFaceLandmarks A value indicating whether the operation should return landmarks of the detected faces.
* @param returnFaceAttributes Analyze and return the one or more specified face attributes in the comma-separated string like "returnFaceAttributes=age,gender". Supported face attributes include age, gender, headPose, smile, facialHair, glasses and emotion. Note that each face attribute analysis has additional computational and time cost.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<DetectedFace> object
*/
public Observable>> detectWithUrlWithServiceResponseAsync(String url, Boolean returnFaceId, Boolean returnFaceLandmarks, List returnFaceAttributes) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (url == null) {
throw new IllegalArgumentException("Parameter url is required and cannot be null.");
}
Validator.validate(returnFaceAttributes);
ImageUrl imageUrl = new ImageUrl();
imageUrl.withUrl(url);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String returnFaceAttributesConverted = this.client.serializerAdapter().serializeList(returnFaceAttributes, CollectionFormat.CSV);
return service.detectWithUrl(returnFaceId, returnFaceLandmarks, returnFaceAttributesConverted, this.client.acceptLanguage(), imageUrl, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> clientResponse = detectWithUrlDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> detectWithUrlDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., APIErrorException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Verify whether two faces belong to a same person. Compares a face Id with a Person Id.
*
* @param faceId FaceId the face, comes from Face - Detect
* @param personGroupId Using existing personGroupId and personId for fast loading a specified person. personGroupId is created in Person Groups.Create.
* @param personId Specify a certain person in a person group. personId is created in Persons.Create.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the VerifyResult object if successful.
*/
public VerifyResult verifyFaceToPerson(UUID faceId, String personGroupId, UUID personId) {
return verifyFaceToPersonWithServiceResponseAsync(faceId, personGroupId, personId).toBlocking().single().body();
}
/**
* Verify whether two faces belong to a same person. Compares a face Id with a Person Id.
*
* @param faceId FaceId the face, comes from Face - Detect
* @param personGroupId Using existing personGroupId and personId for fast loading a specified person. personGroupId is created in Person Groups.Create.
* @param personId Specify a certain person in a person group. personId is created in Persons.Create.
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture verifyFaceToPersonAsync(UUID faceId, String personGroupId, UUID personId, final ServiceCallback serviceCallback) {
return ServiceFuture.fromResponse(verifyFaceToPersonWithServiceResponseAsync(faceId, personGroupId, personId), serviceCallback);
}
/**
* Verify whether two faces belong to a same person. Compares a face Id with a Person Id.
*
* @param faceId FaceId the face, comes from Face - Detect
* @param personGroupId Using existing personGroupId and personId for fast loading a specified person. personGroupId is created in Person Groups.Create.
* @param personId Specify a certain person in a person group. personId is created in Persons.Create.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the VerifyResult object
*/
public Observable verifyFaceToPersonAsync(UUID faceId, String personGroupId, UUID personId) {
return verifyFaceToPersonWithServiceResponseAsync(faceId, personGroupId, personId).map(new Func1, VerifyResult>() {
@Override
public VerifyResult call(ServiceResponse response) {
return response.body();
}
});
}
/**
* Verify whether two faces belong to a same person. Compares a face Id with a Person Id.
*
* @param faceId FaceId the face, comes from Face - Detect
* @param personGroupId Using existing personGroupId and personId for fast loading a specified person. personGroupId is created in Person Groups.Create.
* @param personId Specify a certain person in a person group. personId is created in Persons.Create.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the VerifyResult object
*/
public Observable> verifyFaceToPersonWithServiceResponseAsync(UUID faceId, String personGroupId, UUID personId) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (faceId == null) {
throw new IllegalArgumentException("Parameter faceId is required and cannot be null.");
}
if (personGroupId == null) {
throw new IllegalArgumentException("Parameter personGroupId is required and cannot be null.");
}
if (personId == null) {
throw new IllegalArgumentException("Parameter personId is required and cannot be null.");
}
VerifyFaceToPersonRequest body = new VerifyFaceToPersonRequest();
body.withFaceId(faceId);
body.withPersonGroupId(personGroupId);
body.withPersonId(personId);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
return service.verifyFaceToPerson(this.client.acceptLanguage(), body, parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>() {
@Override
public Observable> call(Response response) {
try {
ServiceResponse clientResponse = verifyFaceToPersonDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse verifyFaceToPersonDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory().newInstance(this.client.serializerAdapter())
.register(200, new TypeToken() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param image An image stream.
* @param detectWithStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws APIErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the List<DetectedFace> object if successful.
*/
public List detectWithStream(byte[] image, DetectWithStreamOptionalParameter detectWithStreamOptionalParameter) {
return detectWithStreamWithServiceResponseAsync(image, detectWithStreamOptionalParameter).toBlocking().single().body();
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param image An image stream.
* @param detectWithStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @param serviceCallback the async ServiceCallback to handle successful and failed responses.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the {@link ServiceFuture} object
*/
public ServiceFuture> detectWithStreamAsync(byte[] image, DetectWithStreamOptionalParameter detectWithStreamOptionalParameter, final ServiceCallback> serviceCallback) {
return ServiceFuture.fromResponse(detectWithStreamWithServiceResponseAsync(image, detectWithStreamOptionalParameter), serviceCallback);
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param image An image stream.
* @param detectWithStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<DetectedFace> object
*/
public Observable> detectWithStreamAsync(byte[] image, DetectWithStreamOptionalParameter detectWithStreamOptionalParameter) {
return detectWithStreamWithServiceResponseAsync(image, detectWithStreamOptionalParameter).map(new Func1>, List>() {
@Override
public List call(ServiceResponse> response) {
return response.body();
}
});
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param image An image stream.
* @param detectWithStreamOptionalParameter the object representing the optional parameters to be set before calling this API
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<DetectedFace> object
*/
public Observable>> detectWithStreamWithServiceResponseAsync(byte[] image, DetectWithStreamOptionalParameter detectWithStreamOptionalParameter) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (image == null) {
throw new IllegalArgumentException("Parameter image is required and cannot be null.");
}
final Boolean returnFaceId = detectWithStreamOptionalParameter != null ? detectWithStreamOptionalParameter.returnFaceId() : null;
final Boolean returnFaceLandmarks = detectWithStreamOptionalParameter != null ? detectWithStreamOptionalParameter.returnFaceLandmarks() : null;
final List returnFaceAttributes = detectWithStreamOptionalParameter != null ? detectWithStreamOptionalParameter.returnFaceAttributes() : null;
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String returnFaceAttributesConverted = this.client.serializerAdapter().serializeList(returnFaceAttributes, CollectionFormat.CSV);
RequestBody imageConverted = RequestBody.create(MediaType.parse("application/octet-stream"), image);
return detectWithStreamWithServiceResponseAsync(image, returnFaceId, returnFaceLandmarks, returnFaceAttributes);
}
/**
* Detect human faces in an image and returns face locations, and optionally with faceIds, landmarks, and attributes.
*
* @param image An image stream.
* @param returnFaceId A value indicating whether the operation should return faceIds of detected faces.
* @param returnFaceLandmarks A value indicating whether the operation should return landmarks of the detected faces.
* @param returnFaceAttributes Analyze and return the one or more specified face attributes in the comma-separated string like "returnFaceAttributes=age,gender". Supported face attributes include age, gender, headPose, smile, facialHair, glasses and emotion. Note that each face attribute analysis has additional computational and time cost.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @return the observable to the List<DetectedFace> object
*/
public Observable>> detectWithStreamWithServiceResponseAsync(byte[] image, Boolean returnFaceId, Boolean returnFaceLandmarks, List returnFaceAttributes) {
if (this.client.azureRegion() == null) {
throw new IllegalArgumentException("Parameter this.client.azureRegion() is required and cannot be null.");
}
if (image == null) {
throw new IllegalArgumentException("Parameter image is required and cannot be null.");
}
Validator.validate(returnFaceAttributes);
String parameterizedHost = Joiner.on(", ").join("{AzureRegion}", this.client.azureRegion());
String returnFaceAttributesConverted = this.client.serializerAdapter().serializeList(returnFaceAttributes, CollectionFormat.CSV);
RequestBody imageConverted = RequestBody.create(MediaType.parse("application/octet-stream"), image);
return service.detectWithStream(returnFaceId, returnFaceLandmarks, returnFaceAttributesConverted, imageConverted, this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
.flatMap(new Func1, Observable>>>() {
@Override
public Observable>> call(Response response) {
try {
ServiceResponse> clientResponse = detectWithStreamDelegate(response);
return Observable.just(clientResponse);
} catch (Throwable t) {
return Observable.error(t);
}
}
});
}
private ServiceResponse> detectWithStreamDelegate(Response response) throws APIErrorException, IOException, IllegalArgumentException {
return this.client.restClient().responseBuilderFactory()., APIErrorException>newInstance(this.client.serializerAdapter())
.register(200, new TypeToken>() { }.getType())
.registerError(APIErrorException.class)
.build(response);
}
}