/** * Outlines a face on the base image with defaults; * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param face - the face. * @return this */ @NotNull public ImageOverlayBuilder outlineFaceOnImage(@NotNull Face face) { return outlineFaceOnImage(face, RectangleType.CORNERED); }
/** * Outlines face on the base image with defaults; * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param face - the faces. * @param rectangleType - the rectangle type. * @return this */ @NotNull public ImageOverlayBuilder outlineFaceOnImage(@NotNull Face face, @NotNull RectangleType rectangleType) { return outlineFaceOnImage(face, rectangleType, DEFAULT_BORDER_WEIGHT); }
/** * Outlines face(s) on the base image with defaults; * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param faces the faces. * @param rectangleType the type of border * @param colourPalette the colour of the border * @return this */ @NotNull public ImageOverlayBuilder outlineFacesOnImage(@NotNull List<Face> faces, @NotNull RectangleType rectangleType, @NotNull CognitiveJColourPalette colourPalette) { faces.forEach(face -> outlineFaceOnImage(face, rectangleType, DEFAULT_BORDER_WEIGHT, colourPalette)); return this; }
/** * Outlines face(s) on the base image with defaults; * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param faces the faces to outline. * @return this */ @NotNull public ImageOverlayBuilder outlineFacesOnImage(@NotNull List<Face> faces) { faces.forEach(face -> outlineFaceOnImage(face, RectangleType.FULL, DEFAULT_BORDER_WEIGHT, CognitiveJColourPalette.randomColour())); return this; }
/** * Outlines face on the base image with defaults; * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param face - the faces. * @param rectangleType - the rectangle type. * @param borderWeight - the weight of the border * @return this */ @NotNull public ImageOverlayBuilder outlineFaceOnImage(@NotNull Face face, @NotNull RectangleType rectangleType, @NotNull BorderWeight borderWeight) { return outlineFaceOnImage(face, rectangleType, borderWeight, CognitiveJColourPalette.randomColour()); }
/** * 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; }
public static void main(String[] args) throws IOException { FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"),System.getProperty("azure.cognitive.emotion.subscriptionKey")); File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic"); //create a new java.io.File from a remote file FileUtils.copyURLToFile(new URL(FILE_LOCATION_OF_US_PRESIDENT), imageFile); FileUtils.forceDeleteOnExit(imageFile); ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile); imageOverlayBuilder.outlineFaceOnImage(faceScenarios.findSingleFace(imageFile), RectangleType.FULL).launchViewer(); } }
public static void main(String[] args) throws IOException { FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"), System.getProperty("azure.cognitive.emotion.subscriptionKey")); File imageFile = File.createTempFile("DetectSingleFaceFromFileExample", "pic"); //create a new java.io.File from a remote file FileUtils.copyURLToFile(new URL(IMAGE_LOCATION), imageFile); FileUtils.forceDeleteOnExit(imageFile); ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(imageFile); CognitiveJColourPalette colourPalette = CognitiveJColourPalette.STRAWBERRY; List<Face> faces = faceScenarios.findFaces(imageFile); faces.forEach(face -> imageOverlayBuilder.outlineFaceOnImage(face, RectangleType.FULL, ImageOverlayBuilder.DEFAULT_BORDER_WEIGHT, colourPalette).writeAge(face, colourPalette, RectangleTextPosition.TOP_OF)); imageOverlayBuilder.launchViewer(); } }
/** * 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; }
public static void main(String[] args) throws IOException { FaceScenarios faceScenarios = new FaceScenarios(System.getProperty("azure.cognitive.subscriptionKey"), System.getProperty("azure.cognitive.emotion.subscriptionKey")); ImageOverlayBuilder imageOverlayBuilder = ImageOverlayBuilder.builder(FILE_LOCATION_OF_US_PRESIDENT); Face face = faceScenarios.findSingleFace(FILE_LOCATION_OF_US_PRESIDENT); imageOverlayBuilder.outlineFaceOnImage(face, RectangleType.FULL, ImageOverlayBuilder.DEFAULT_BORDER_WEIGHT, CognitiveJColourPalette.POPPY).writeGenderAndAge(face, CognitiveJColourPalette.POPPY).launchViewer(); } }