public Person createPersonInGroup(final String personGroupId, String personName, boolean createGroupIfMissing) { if (createGroupIfMissing) { boolean exists = !Utils.throwsException(() -> personGroupBuilder.getGroup(personGroupId), PersonGroupNotFoundException.class); if (!exists) { personGroupBuilder.createGroup(personGroupId, personGroupId, ""); } } return personBuilder.createPerson(personGroupId, personName, "").withResult(); }
public void createGroupWithFromVisionImages(@NotNull String faceListId, @NotNull List<VisionImage> visionImages) { Validation.validateArray(visionImages, 1, 1000, new ParameterValidationException("visionImages", "Face list is invalid. min 1, max 1000")); boolean exists = !Utils.throwsException(() -> faceListBuilder.getFaceList(faceListId).withResult(), FaceListNotFoundException.class); if (!exists) { faceListBuilder.createFaceList(faceListId, faceListId, "").withNoResult(); } visionImages.forEach(it -> { if (it.isLocalFile()) faceListBuilder.addFaceToFaceList(faceListId, "", "", Utils.fileToFileInputStream((File) it.getImage())).withNoResult(); else faceListBuilder.addFaceToFaceList(faceListId, "", "", (String) it.getImage()).withNoResult(); }); }
/** * Create a new group from a set of people * * @param personGroupId the person group id * @param people the people in the group * @return The created personGroupId */ public String createGroupWithPeople(@NotNull String personGroupId, @NotNull People people) { Validation.validateArray(people.simplePersons(), 1, 1000, new ParameterValidationException("people", "People list is invalid. min 1, max 1000")); boolean exists = !Utils.throwsException(() -> personGroupBuilder.getGroup(personGroupId).withResult(), PersonGroupNotFoundException.class); if (!exists) { personGroupBuilder.createGroup(personGroupId, personGroupId, "").withNoResult(); } people.simplePersons().stream().forEach(simplePerson -> { Person person = personBuilder.createPerson(personGroupId, simplePerson.personName, simplePerson.personUserData).withResult(); List<ImageHolder> personImages = simplePerson.personImages; for (ImageHolder imageHolder : personImages) { if (imageHolder.firstImage().isLocalFile()) personBuilder.addFaceToPerson(personGroupId, person.personId, "", (File) imageHolder.firstImage().getImage()).withNoResult(); else personBuilder.addFaceToPerson(personGroupId, person.personId, "", (String) imageHolder.firstImage().getImage()).withNoResult(); } }); personGroupBuilder.trainGroup(personGroupId).withNoResult(); return personGroupId; }