use of com.google.api.services.vision.v1.model.Vertex in project java-docs-samples by GoogleCloudPlatform.
the class FaceDetectApp method annotateWithFace.
/**
* Annotates an image {@code img} with a polygon defined by {@code face}.
*/
private static void annotateWithFace(BufferedImage img, FaceAnnotation face) {
Graphics2D gfx = img.createGraphics();
Polygon poly = new Polygon();
for (Vertex vertex : face.getFdBoundingPoly().getVertices()) {
poly.addPoint(vertex.getX(), vertex.getY());
}
gfx.setStroke(new BasicStroke(5));
gfx.setColor(new Color(0x00ff00));
gfx.draw(poly);
}
use of com.google.api.services.vision.v1.model.Vertex in project java-docs-samples by GoogleCloudPlatform.
the class FaceDetectAppTest method annotateWithFaces_manyFaces_outlinesFaces.
@Test
public void annotateWithFaces_manyFaces_outlinesFaces() throws Exception {
// Arrange
ImmutableList<FaceAnnotation> faces = ImmutableList.of(new FaceAnnotation().setFdBoundingPoly(new BoundingPoly().setVertices(ImmutableList.of(new Vertex().setX(10).setY(5), new Vertex().setX(20).setY(5), new Vertex().setX(20).setY(25), new Vertex().setX(10).setY(25)))), new FaceAnnotation().setFdBoundingPoly(new BoundingPoly().setVertices(ImmutableList.of(new Vertex().setX(60).setY(50), new Vertex().setX(70).setY(60), new Vertex().setX(50).setY(60)))));
BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
// Act
FaceDetectApp.annotateWithFaces(img, faces);
// Assert
assertThat(img.getRGB(10, 5) & 0x00ff00).named("img face #1 vertex (10, 5) green channel").isEqualTo(0x00ff00);
assertThat(img.getRGB(20, 5) & 0x00ff00).named("img face #1 vertex (20, 5) green channel").isEqualTo(0x00ff00);
assertThat(img.getRGB(20, 25) & 0x00ff00).named("img face #1 vertex (20, 25) green channel").isEqualTo(0x00ff00);
assertThat(img.getRGB(10, 25) & 0x00ff00).named("img face #1 vertex (10, 25) green channel").isEqualTo(0x00ff00);
assertThat(img.getRGB(60, 50) & 0x00ff00).named("img face #2 vertex (60, 50) green channel").isEqualTo(0x00ff00);
assertThat(img.getRGB(70, 60) & 0x00ff00).named("img face #2 vertex (70, 60) green channel").isEqualTo(0x00ff00);
assertThat(img.getRGB(50, 60) & 0x00ff00).named("img face #2 vertex (50, 60) green channel").isEqualTo(0x00ff00);
}
Aggregations