use of com.ibm.watson.developer_cloud.visual_recognition.v3.model.ImageWithFaces 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.ImageWithFaces in project jbpm-work-items by kiegroup.
the class WatsonWorkitemHandlerTest method setUp.
// @Mock
// Face recognitionFace;
@Before
public void setUp() {
// image classification
ClassResult classResultObj = new ClassResult();
classResultObj.setClassName("testClassName");
classResultObj.setScore(new Float(1));
classResultObj.setTypeHierarchy("testTypeHierarchy");
List<ClassifiedImage> classifiedImageList = new ArrayList<>();
classifiedImageList.add(associationClassifiedImage);
List<ClassifierResult> classifierResults = new ArrayList<>();
classifierResults.add(associationClassifierResult);
List<ClassResult> classResults = new ArrayList<>();
classResults.add(classResultObj);
when(associationService.classify(any(ClassifyOptions.class))).thenReturn(associationServiceCall);
when(associationServiceCall.execute()).thenReturn(assoiationClassifiedImages);
when(assoiationClassifiedImages.getImages()).thenReturn(classifiedImageList);
when(associationClassifiedImage.getClassifiers()).thenReturn(classifierResults);
when(associationClassifierResult.getClasses()).thenReturn(classResults);
when(associationClassifierResult.getClassifierId()).thenReturn("testClassifierId");
// face detection
List<ImageWithFaces> recognitionImageList = new ArrayList<>();
recognitionImageList.add(recognitionImageWithFaces);
FaceAge recognitionFaceAge = new FaceAge();
recognitionFaceAge.setMin(20);
recognitionFaceAge.setMax(35);
FaceGender recognitionFaceGender = new FaceGender();
recognitionFaceGender.setGender("male");
FaceIdentity recognitionFaceIdentity = new FaceIdentity();
recognitionFaceIdentity.setName("testPerson");
Face recognitionFace = new Face();
recognitionFace.setAge(recognitionFaceAge);
recognitionFace.setGender(recognitionFaceGender);
recognitionFace.setIdentity(recognitionFaceIdentity);
List<Face> recognitionFaceList = new ArrayList<>();
recognitionFaceList.add(recognitionFace);
when(recognitionService.detectFaces(any(DetectFacesOptions.class))).thenReturn(recognitionServiceCall);
when(recognitionServiceCall.execute()).thenReturn(recognitionDetectFaces);
when(recognitionDetectFaces.getImages()).thenReturn(recognitionImageList);
when(recognitionImageWithFaces.getFaces()).thenReturn(recognitionFaceList);
when(recognitionImageWithFaces.getImage()).thenReturn("testImage");
}
Aggregations