/** * write out the faces gender and age (formatted '%Gender, Age %.1f') to the top of the face rectangle. * ({@link ImageOverlayBuilder#outlineFaceOnImage(Face, RectangleType, BorderWeight, CognitiveJColourPalette)} * * @param face the face. * @param colourPalette the color to paint the text * @param borderWeight borderWeight to use * @return this */ @NotNull public ImageOverlayBuilder writeGenderAndAge(@NotNull Face face, @NotNull CognitiveJColourPalette colourPalette, @NotNull BorderWeight borderWeight) { return writeGenderAndAge(face, colourPalette, borderWeight.insets()); }
private void drawRectangle(Graphics2D workingGraphics, Rectangle rectangle, Color color, BorderWeight borderWeight) { workingGraphics.setColor(color); workingGraphics.setStroke(new BasicStroke(borderWeight.thickness())); workingGraphics.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height); }
private void drawRectangle(Graphics2D workingGraphics, Rectangle rectangle, Color color, BorderWeight borderWeight, boolean fillRect) { workingGraphics.setColor(color); workingGraphics.setStroke(new BasicStroke(borderWeight.thickness())); if (fillRect) workingGraphics.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height); else workingGraphics.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height); }
@NotNull @Override public BufferedImage applyFilter(@NotNull BufferedImage bufferedImage) { Graphics2D graphics2D = bufferedImage.createGraphics(); rectangle.stream().filter(point -> point != null).forEach(point -> drawRectangle(graphics2D, new Rectangle(point.x, point.y, borderWeight.thickness(), borderWeight.thickness()), color.getBackground(), borderWeight)); graphics2D.dispose(); return bufferedImage; }
public void drawCornerRectangle(Graphics2D workingGraphics, Color color, BorderWeight borderWeight, Rectangle rectangle) { workingGraphics.setColor(color); workingGraphics.setStroke(new BasicStroke(borderWeight.thickness())); int cornerLength = rectangle.width / 6; if ((rectangle.width < 0) || (rectangle.height < 0)) { return; } //left up corner workingGraphics.drawLine(rectangle.x, rectangle.y, rectangle.x + cornerLength, rectangle.y); workingGraphics.drawLine(rectangle.x, rectangle.y, rectangle.x, rectangle.y + cornerLength); //right up corner workingGraphics.drawLine(rectangle.x + rectangle.width, rectangle.y, (rectangle.x + rectangle.width) - cornerLength, rectangle.y); workingGraphics.drawLine(rectangle.x + rectangle.width, rectangle.y, rectangle.x + rectangle.width, rectangle.y + cornerLength); //left down corner workingGraphics.drawLine(rectangle.x, rectangle.y + rectangle.height, rectangle.x + cornerLength, rectangle.y + rectangle.height); workingGraphics.drawLine(rectangle.x, rectangle.y + rectangle.height, rectangle.x, (rectangle.y + rectangle.height) - cornerLength); //right down corner workingGraphics.drawLine(rectangle.x + rectangle.width, rectangle.y + rectangle.height, (rectangle.x + rectangle.width) - cornerLength, rectangle.y + rectangle.height); workingGraphics.drawLine(rectangle.x + rectangle.width, rectangle.y + rectangle.height, rectangle.x + rectangle.width, (rectangle.y + rectangle.height) - cornerLength); }
/** * 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; }
@NotNull @Override public BufferedImage applyFilter(@NotNull BufferedImage bufferedImage) { Graphics2D graphics2D = bufferedImage.createGraphics(); graphics2D.setColor(color.getBackground()); graphics2D.setStroke(new BasicStroke(lineThickness.thickness())); Point leftRectangleBottom = new Point(rectangle1.x + rectangle1.width, rectangle1.y + rectangle1.height); Point leftRectangleTop = new Point(rectangle1.x + rectangle1.width, rectangle1.y); Point rightRectangleTop = new Point(rectangle2.x + xOffset, rectangle2.y + insets.top); Point rightRectangleBottom = new Point(rectangle2.x + xOffset, rectangle2.y + insets.top + rectangle2.height); PointDistance pointDistance = calculatePoints(leftRectangleTop, leftRectangleBottom, rightRectangleTop, rightRectangleBottom); graphics2D.drawLine(pointDistance.getLeftPoint().x, pointDistance.getLeftPoint().y, pointDistance.getRightPoint().x, pointDistance.getRightPoint().y); graphics2D.dispose(); return bufferedImage; }