/** * Apply a title to the base image. * * @param location where to locate the title. * @param font the font to use. * @param color the color * @param text the title * @return this */ @NotNull public ImageOverlayBuilder titleImage(PointLocations location, Font font, @NotNull CognitiveJColourPalette color, @NotNull String text) { ApplyCaptionOutsideImageFilter applyCaptionOutsideImageFilter = new ApplyCaptionOutsideImageFilter(location, font, color, text); bufferedImage = applyCaptionOutsideImageFilter.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; }
private static void buildGrid(ImageOverlayBuilder imageOverlayBuilder, People people) { ImageGrid candidates = new ImageGrid(extractImagesFromPeople(people), 4); ApplyCaptionOutsideImageFilter applyCaptionOutsideImageFilter = new ApplyCaptionOutsideImageFilter(PointLocations.TOP_CENTER, ImageOverlayBuilder.DEFAULT_TEXT_FONT, CognitiveJColourPalette.WHITE, "Candidate Dataset"); BufferedImage mergeImage = applyCaptionOutsideImageFilter.applyFilter(candidates.build()); imageOverlayBuilder.mergeImage(mergeImage); }
public static BufferedImage loadAndNameCandidateImages(ImageHolder imageHolder) { try { BufferedImage thumbnail = Thumbnails.of(new URL((String) imageHolder.firstImage().getImage())) .crop(Positions.CENTER).size(200, 200).asBufferedImage(); ApplyCaptionOutsideImageFilter applyCaptionOutsideImageFilter = new ApplyCaptionOutsideImageFilter(PointLocations.BOTTOM_CENTER, ImageOverlayBuilder.DEFAULT_TEXT_FONT, CognitiveJColourPalette.WHITE, imageHolder.getName()); return applyCaptionOutsideImageFilter.applyFilter(thumbnail); } catch (IOException e) { throw new CognitiveException("Could not make thumbnail", e); } } }