/** * write out the faces age (formatted 'Age %.1f') to the top of the face rectangle. * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param face the face. * @param colourPalette the colour to use * @param textPosition location of the text boundary * @return this */ @NotNull public ImageOverlayBuilder writeAge(@NotNull Face face, @NotNull CognitiveJColourPalette colourPalette, @NotNull RectangleTextPosition textPosition) { TextOnRectangleFilter textOnRectangleFilter = new TextOnRectangleFilter(new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()), face.faceRectangle.asAwtRectangle(), new Insets(0, 0, 0, 0), DEFAULT_TEXT_FONT, colourPalette, textPosition, String.format("Age %.2f", face.faceAttributesResp.age)); bufferedImage = textOnRectangleFilter.applyFilter(bufferedImage); return this; }
/** * write out the faces' {@link FaceAttributes} * * @param face the face. * @param colourPalette the colour to use * @param textPosition position to locate the text * @return this */ @NotNull public ImageOverlayBuilder writeFaceAttributes(@NotNull Face face, @NotNull CognitiveJColourPalette colourPalette, RectangleTextPosition textPosition) { TextOnRectangleFilter textOnRectangleFilter = new TextOnRectangleFilter(new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()), face.faceRectangle.asAwtRectangle(), new Insets(0, 0, 0, 0), DEFAULT_TEXT_FONT, colourPalette, textPosition, FaceStringBuilder.buildStringFor(face, FaceAttributes.ALL)); bufferedImage = textOnRectangleFilter.applyFilter(bufferedImage); return this; }
@NotNull private ImageOverlayBuilder outlineOCRWord(@NotNull OCRResult.Word word) { OverlayRectangleFilter overlayRectangleFilter = new OverlayRectangleFilter(word.boundingBoxAsAwtRectangle(), RectangleType.FULL, BorderWeight.THINNER, CognitiveJColourPalette.randomColour()); TextOnRectangleFilter textOnRectangleFilter = new TextOnRectangleFilter(new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()), word.boundingBoxAsAwtRectangle(), new Insets(0, 0, 0, 0), new Font("Noto Sans", Font.PLAIN, 12), CognitiveJColourPalette.TRANS_GRAY, RectangleTextPosition.BOTTOM_OF, word.text); bufferedImage = textOnRectangleFilter.applyFilter(overlayRectangleFilter.applyFilter(bufferedImage)); return this; }
/** * write out the faces gender and age (formatted '%Gender, Age %.1f') * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param face the face. * @param colourPalette the colors to use * @param insets any Insets to take into consideration(e.g. border thickness). * @param textPosition where to position the text container * @return this */ public ImageOverlayBuilder writeGenderAndAge(Face face, CognitiveJColourPalette colourPalette, @NotNull Insets insets, RectangleTextPosition textPosition) { TextOnRectangleFilter textOnRectangleFilter = new TextOnRectangleFilter(new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()), face.faceRectangle.asAwtRectangle(), insets, DEFAULT_TEXT_FONT, colourPalette, textPosition, String.format("%s, Age %.1f", WordUtils.capitalize(face.faceAttributesResp.gender.name()), face.faceAttributesResp.age)); bufferedImage = textOnRectangleFilter.applyFilter(bufferedImage); return this; }
/** * Draw the rectangle and displays all @{@link Emotion} for the face. * * @param emotion all found emotions. * @param textPosition where to position the emotion * @return this */ @NotNull public ImageOverlayBuilder outlineEmotionOnImage(@NotNull Emotion emotion, @NotNull RectangleTextPosition textPosition) { OverlayRectangleFilter overlayRectangleFilter = new OverlayRectangleFilter(emotion.faceRectangle.asAwtRectangle(), RectangleType.CORNERED, DEFAULT_BORDER_WEIGHT, CognitiveJColourPalette.randomColour()); TextOnRectangleFilter textOnRectangleFilter = new TextOnRectangleFilter(new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()), emotion.faceRectangle.asAwtRectangle(), new Insets(0, 0, 0, 0), new Font("Noto Sans", Font.PLAIN, 40), CognitiveJColourPalette.GRAY, textPosition, EmotionStringBuilder.listAllEmotions(emotion)); bufferedImage = textOnRectangleFilter.applyFilter(overlayRectangleFilter.applyFilter(bufferedImage)); return this; }
/** * Draw the rectangle and outline the dominant @{@link Emotion} * * @param emotion the emotion * @param textPosition where the text is to be positioned * @return this */ @NotNull public ImageOverlayBuilder outlineDominantEmotionOnImage(@NotNull Emotion emotion, @NotNull RectangleTextPosition textPosition) { OverlayRectangleFilter overlayRectangleFilter = new OverlayRectangleFilter(emotion.faceRectangle.asAwtRectangle(), RectangleType.CORNERED, DEFAULT_BORDER_WEIGHT, CognitiveJColourPalette.STRAWBERRY); TextOnRectangleFilter textOnRectangleFilter = new TextOnRectangleFilter(new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()), emotion.faceRectangle.asAwtRectangle(), new Insets(0, 0, 0, 0), DEFAULT_TEXT_FONT, CognitiveJColourPalette.STRAWBERRY, textPosition, EmotionStringBuilder.dominantEmotion(emotion)); bufferedImage = textOnRectangleFilter.applyFilter(overlayRectangleFilter.applyFilter(bufferedImage)); return this; }
/** * tags identified faces. * * @param identificationSet a set of identifications. * @param textPosition * @return this */ @NotNull public ImageOverlayBuilder identify(@NotNull IdentificationSet identificationSet, @NotNull RectangleTextPosition textPosition) { CognitiveJColourPalette identificationColor = identificationSet.isIdentified() ? CognitiveJColourPalette.GREEN : CognitiveJColourPalette.RED; Face candidateFace = identificationSet.getCandidateFace(); outlineFaceOnImage(candidateFace, RectangleType.CORNERED, DEFAULT_BORDER_WEIGHT, identificationColor); TextOnRectangleFilter textOnRectangleFilter = new TextOnRectangleFilter(new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()), candidateFace.faceRectangle.asAwtRectangle(), new Insets(DEFAULT_BORDER_WEIGHT.thickness(), DEFAULT_BORDER_WEIGHT.thickness(), DEFAULT_BORDER_WEIGHT.thickness(), DEFAULT_BORDER_WEIGHT.thickness()), DEFAULT_TEXT_FONT, identificationColor, textPosition, identificationSet.isIdentified() ? identificationSet.getIdentifiedPerson().name : "Unknown"); bufferedImage = textOnRectangleFilter.applyFilter(bufferedImage); return this; }