use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces in project jbpm-work-items by kiegroup.
the class DetectFacesWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
Document detectionImage = (Document) workItem.getParameter("ImageToDetect");
Map<String, Object> widResults = new HashMap<String, Object>();
if (detectionImage != null) {
try {
VisualRecognition service = auth.getService(apiKey);
ByteArrayInputStream imageStream = new ByteArrayInputStream(detectionImage.getContent());
DetectFacesOptions detectFacesOptions = new DetectFacesOptions.Builder().imagesFile(imageStream).build();
DetectedFaces result = service.detectFaces(detectFacesOptions).execute();
if (result == null || result.getImages() == null || result.getImages().size() < 1) {
logger.error("Unable to detect faces on provided image.");
workItemManager.abortWorkItem(workItem.getId());
} else {
List<FaceDetectionResult> resultList = new ArrayList<>();
for (ImageWithFaces imageWithFaces : result.getImages()) {
for (Face face : imageWithFaces.getFaces()) {
resultList.add(new FaceDetectionResult(imageWithFaces, face));
}
}
widResults.put(RESULT_VALUE, resultList);
workItemManager.completeWorkItem(workItem.getId(), widResults);
}
} catch (Exception e) {
handleException(e);
}
} else {
logger.error("Missing image for face detection.");
throw new IllegalArgumentException("Missing image for face detection.");
}
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces in project java-sdk by watson-developer-cloud.
the class VisualRecognition method detectFaces.
/**
* Detect faces in images.
*
* **Important:** On April 2, 2018, the identity information in the response to calls to the Face model was removed.
* The identity information refers to the `name` of the person, `score`, and `type_hierarchy` knowledge graph. For
* details about the enhanced Face model, see the [Release
* notes](https://console.bluemix.net/docs/services/visual-recognition/release-notes.html#2april2018). Analyze and get
* data about faces in images. Responses can include estimated age and gender. This feature uses a built-in model, so
* no training is necessary. The Detect faces method does not support general biometric facial recognition. Supported
* image formats include .gif, .jpg, .png, and .tif. The maximum image size is 10 MB. The minimum recommended pixel
* density is 32X32 pixels per inch.
*
* @param detectFacesOptions the {@link DetectFacesOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link DetectedFaces}
*/
public ServiceCall<DetectedFaces> detectFaces(DetectFacesOptions detectFacesOptions) {
Validator.notNull(detectFacesOptions, "detectFacesOptions cannot be null");
Validator.isTrue((detectFacesOptions.imagesFile() != null) || (detectFacesOptions.url() != null) || (detectFacesOptions.parameters() != null), "At least one of imagesFile, url, or parameters must be supplied.");
String[] pathSegments = { "v3/detect_faces" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
if (detectFacesOptions.imagesFile() != null) {
RequestBody imagesFileBody = RequestUtils.inputStreamBody(detectFacesOptions.imagesFile(), detectFacesOptions.imagesFileContentType());
multipartBuilder.addFormDataPart("images_file", detectFacesOptions.imagesFilename(), imagesFileBody);
}
if (detectFacesOptions.parameters() != null) {
multipartBuilder.addFormDataPart("parameters", detectFacesOptions.parameters());
}
if (detectFacesOptions.url() != null) {
multipartBuilder.addFormDataPart("url", detectFacesOptions.url());
}
builder.body(multipartBuilder.build());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DetectedFaces.class));
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testDetectFacesFromFile.
/**
* Test detect faces from file.
*
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testDetectFacesFromFile() throws FileNotFoundException {
File images = new File(IMAGE_FACE_FILE);
DetectFacesOptions options = new DetectFacesOptions.Builder().imagesFile(images).build();
DetectedFaces detectedFaces = service.detectFaces(options).execute();
assertDetectedFaces(detectedFaces, options);
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testDetectFacesFromUrlUsingParameters.
/**
* Test detect faces from url using the deprecated parameters option.
*/
@Test
public void testDetectFacesFromUrlUsingParameters() {
String parameters = "{\"url\":\"" + IMAGE_FACE_URL + "\"}";
DetectFacesOptions options = new DetectFacesOptions.Builder().parameters(parameters).build();
DetectedFaces detectedFaces = service.detectFaces(options).execute();
assertDetectedFaces(detectedFaces, options);
}
use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.DetectedFaces in project java-sdk by watson-developer-cloud.
the class VisualRecognitionIT method testDetectFacesFromUrl.
/**
* Test detect faces from url.
*/
@Test
public void testDetectFacesFromUrl() {
DetectFacesOptions options = new DetectFacesOptions.Builder().url(IMAGE_FACE_URL).build();
DetectedFaces detectedFaces = service.detectFaces(options).execute();
assertDetectedFaces(detectedFaces, options);
}
Aggregations