Skip to content
This repository was archived by the owner on Nov 8, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ public String toString() {
*/
Face[] detect(InputStream imageStream, boolean returnFaceId, boolean returnFaceLandmarks, FaceAttributeType[] returnFaceAttributes) throws ClientException, IOException;

/**
* Detects faces in an uploaded image.
* @param imageStream The image stream.
* @param returnFaceId If set to <c>true</c> [return face ID].
* @param returnFaceLandmarks If set to <c>true</c> [return face landmarks]
* @param returnFaceAttributes Return face attributes.
* @param recognitionModel specific of recognition model to detect the face
* @return detected faces.
* @throws ClientException
* @throws IOException
*/
Face[] detect(InputStream imageStream, boolean returnFaceId, boolean returnFaceLandmarks, FaceAttributeType[] returnFaceAttributes, String recognitionModel) throws ClientException, IOException;

/**
* Verifies whether the specified two faces belong to the same person.
* @param faceId1 The face id 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,50 @@ public Face[] detect(InputStream imageStream, boolean returnFaceId, boolean retu
return faces.toArray(new Face[faces.size()]);
}

@Override
public Face[] detect(InputStream imageStream, boolean returnFaceId, boolean returnFaceLandmarks, FaceAttributeType[] returnFaceAttributes, String recognitionModel) throws ClientException, IOException {
Map<String, Object> params = new HashMap<>();

params.put("returnFaceId", returnFaceId);
params.put("returnFaceLandmarks", returnFaceLandmarks);
if (returnFaceAttributes != null && returnFaceAttributes.length > 0) {
StringBuilder faceAttributesStringBuilder = new StringBuilder();
boolean firstAttribute = true;
for (FaceAttributeType faceAttributeType: returnFaceAttributes)
{
if (firstAttribute) {
firstAttribute = false;
} else {
faceAttributesStringBuilder.append(",");
}

faceAttributesStringBuilder.append(faceAttributeType);
}
params.put("returnFaceAttributes", faceAttributesStringBuilder.toString());
}
params.put("recognitionModel", (recognitionModel == null || !recognitionModel.matches("recognition_0[12]")) ? "recognition_01" : recognitionModel);

String path = String.format("%s/%s", mServiceHost, DETECT_QUERY);
String uri = WebServiceRequest.getUrl(path, params);

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int bytesRead;
byte[] bytes = new byte[1024];
while ((bytesRead = imageStream.read(bytes)) > 0) {
byteArrayOutputStream.write(bytes, 0, bytesRead);
}
byte[] data = byteArrayOutputStream.toByteArray();
params.clear();
params.put(DATA, data);

String json = (String)mRestCall.request(uri, RequestMethod.POST, params, STREAM_DATA);
Type listType = new TypeToken<List<Face>>() {
}.getType();
List<Face> faces = mGson.fromJson(json, listType);

return faces.toArray(new Face[faces.size()]);
}

@Override
public VerifyResult verify(UUID faceId1, UUID faceId2) throws ClientException, IOException {
Map<String, Object> params = new HashMap<>();
Expand Down