@NotNull public ImageOverlayBuilder outlineFaceOnImage(@NotNull Face face, @NotNull RectangleType rectangleType, @NotNull BorderWeight borderWeight, @NotNull CognitiveJColourPalette colourPalette) { OverlayRectangleFilter overlayRectangleFilter = new OverlayRectangleFilter(face.faceRectangle.asAwtRectangle(), rectangleType, borderWeight, colourPalette); bufferedImage = overlayRectangleFilter.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; }
@NotNull private ImageOverlayBuilder outlineOCRLine(OCRResult.Line line) { OverlayRectangleFilter overlayRectangleFilter = new OverlayRectangleFilter(line.boundingBoxAsAwtRectangle(), RectangleType.FULL, BorderWeight.THINNER, CognitiveJColourPalette.randomColour()); bufferedImage = overlayRectangleFilter.applyFilter(bufferedImage); line.words.forEach(this::outlineOCRWord); 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; }
/** * Draws a verification graphic for the base image and the passed image. * * @param candidateImage - the passed image. * @param verificationSet - a verification set to be drawn. * @return this */ @NotNull public ImageOverlayBuilder verify(@NotNull BufferedImage candidateImage, @NotNull VerificationSet verificationSet) { CognitiveJColourPalette verificationColor = verificationSet.getVerification().isIdentical ? CognitiveJColourPalette.GREEN : CognitiveJColourPalette.RED; outlineFaceOnImage(verificationSet.getFirstFace(), RectangleType.CORNERED, BorderWeight.THICK, verificationColor); OverlayRectangleFilter overlayRectangleFilter = new OverlayRectangleFilter(verificationSet.getSecondFace().faceRectangle.asAwtRectangle(), RectangleType.CORNERED, BorderWeight.THICK, verificationColor); MergeImagesFilter mergeImagesFilter = new MergeImagesFilter(overlayRectangleFilter.applyFilter(candidateImage), SMALL_PADDING, MergeImagesFilter.Position.RIGHT); LineJoinRectangleFilter lineJoinRectangleFilter = new LineJoinRectangleFilter(verificationSet.getFirstFace().faceRectangle.asAwtRectangle(), verificationSet.getSecondFace().faceRectangle.asAwtRectangle(), BorderWeight.THICK, verificationColor, bufferedImage.getWidth(), SMALL_PADDING); Verification verification = verificationSet.getVerification(); ApplyCaptionOutsideImageFilter applyCaptionOutsideImageFilter = new ApplyCaptionOutsideImageFilter(PointLocations.BOTTOM_CENTER, DEFAULT_TEXT_FONT.deriveFont(80f).deriveFont(80f), verificationColor, verification.isIdentical ? String.format("Match (confidence %.3f)", verification.confidence) : String.format("No Match (confidence %.3f)", verification.confidence)); bufferedImage = applyCaptionOutsideImageFilter.applyFilter(lineJoinRectangleFilter.applyFilter(mergeImagesFilter.applyFilter(bufferedImage))); return this; }