@NotNull public List<Face> findFaces(@NotNull File imageFile) { return findFaces(Utils.fileToFileInputStream(imageFile)); }
/** * Add a representative face to a person for identification. The input face is specified as an image with a targetFace rectangle. It returns an persistedFaceId representing the added face and this persistedFaceId will not expire. * <p> * The persistedFaceId is only used in Face - Identify and Person - Delete a Person Face * Each person has a maximum of 248 faces. * <p> * JPEG, PNG, GIF(the first frame), and BMP are supported. The image file size should be no larger than 4MB. * <p> * The detectable face size is between 36x36 to 4096x4096 pixels. The faces out of this range will not be detected. * <p> * Rectangle specified by targetFace should contain exactly one face. Zero or multiple faces will be regarded as an error. Out of detectable face size, large head-pose, or very large occlusions will also result in fail to add a person face. * <p> * The given rectangle specifies both face location and face size at the same time. There is no guarantee of corrent result if you are using rectangle which are not returned from Face - Detect. * * @param personGroupId The target person's belonging person group's ID. * @param personId Target person that the face is added to. * @param userData Optional fields for user-provided data attached to a person. Size limit is 16KB. * @param image Face image image (as a file). Valid image size is from 1KB to 4MB. Only one face is allowed per image. * @return a built {@link AddFaceToPersonAction} * @see <a href="https://dev.projectoxford.ai/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f3039523b">MS Cognitive Docs (Person - Add a Person Face)</a> */ @NotNull public AddFaceToPersonAction addFaceToPerson(@NotNull String personGroupId, @NotNull String personId, String userData, File image) { return addFaceToPerson(personGroupId, personId, userData, Utils.fileToFileInputStream(image)); }
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(); }); }
/** * Creates a {@link cognitivej.vision.face.facelist.FaceList} and add a number of images to the newly created list. * * @param faceListName - the name of the face list to be created. * @param holdingImages - a list of file of type {@link ImageHolder} * @return the faceListId of the created {@link cognitivej.vision.face.facelist.FaceList}. */ public String createFaceListAndAddFiles(String faceListName, List<ImageHolder> holdingImages) { String faceListId = String.format("%s_%s_%s", faceListName, RandomStringUtils.randomAlphabetic(3).toLowerCase(), RandomStringUtils.randomNumeric(3)); faceListBuilder.createFaceList(faceListId, faceListName, null).withNoResult(); holdingImages.forEach((ImageHolder it) -> { if (it.firstImage().isLocalFile()) faceListBuilder.addFaceToFaceList(faceListId, it.getUserData(), "", Utils.fileToFileInputStream((File) it.firstImage().getImage())).withNoResult(); else faceListBuilder.addFaceToFaceList(faceListId, it.getUserData(), "", (String) it.firstImage().getImage()).withNoResult(); }); return faceListId; }