Search in sources :

Example 1 with Point

use of com.amazonaws.services.textract.model.Point in project aws-doc-sdk-examples by awsdocs.

the class AnalyzeDocument method ShowPolygon.

// Shows polygon at supplied location
private void ShowPolygon(int imageHeight, int imageWidth, List<Point> points, Graphics2D g2d) {
    g2d.setColor(new Color(0, 0, 0));
    Polygon polygon = new Polygon();
    // Construct polygon and display
    for (Point point : points) {
        polygon.addPoint((Math.round(point.getX() * imageWidth)), Math.round(point.getY() * imageHeight));
    }
    g2d.drawPolygon(polygon);
}
Also used : Point(com.amazonaws.services.textract.model.Point)

Example 2 with Point

use of com.amazonaws.services.textract.model.Point in project aws-doc-sdk-examples by awsdocs.

the class DocumentText method ShowPolygon.

// Shows polygon at supplied location
private void ShowPolygon(int imageHeight, int imageWidth, List<Point> points, Graphics2D g2d) {
    g2d.setColor(new Color(0, 0, 0));
    Polygon polygon = new Polygon();
    // Construct polygon and display
    for (Point point : points) {
        polygon.addPoint((Math.round(point.getX() * imageWidth)), Math.round(point.getY() * imageHeight));
    }
    g2d.drawPolygon(polygon);
}
Also used : Point(com.amazonaws.services.textract.model.Point)

Example 3 with Point

use of com.amazonaws.services.textract.model.Point in project amplify-android by aws-amplify.

the class TextractResultTransformersTest method randomPolygon.

private List<Point> randomPolygon() {
    final int minPoints = 3;
    List<Point> points = new ArrayList<>();
    for (int i = 0; i < minPoints; i++) {
        points.add(new Point().withX(random.nextFloat()).withY(random.nextFloat()));
    }
    return points;
}
Also used : ArrayList(java.util.ArrayList) Point(com.amazonaws.services.textract.model.Point) Point(com.amazonaws.services.textract.model.Point)

Example 4 with Point

use of com.amazonaws.services.textract.model.Point in project amplify-android by aws-amplify.

the class TextractResultTransformersTest method testPolygonConversion.

/**
 * Tests that the polygonal boundary from Textract in the form
 * of list of points is converted to an Amplify shape for polygons.
 */
@Test
public void testPolygonConversion() {
    List<Point> randomPolygon = randomPolygon();
    Polygon polygon = TextractResultTransformers.fromPoints(randomPolygon);
    List<PointF> actualPoints = polygon.getPoints();
    List<PointF> expectedPoints = new ArrayList<>();
    for (Point point : randomPolygon) {
        expectedPoints.add(new PointF(point.getX(), point.getY()));
    }
    assertEquals(expectedPoints, actualPoints);
}
Also used : PointF(android.graphics.PointF) ArrayList(java.util.ArrayList) Point(com.amazonaws.services.textract.model.Point) Polygon(com.amplifyframework.predictions.models.Polygon) Test(org.junit.Test)

Example 5 with Point

use of com.amazonaws.services.textract.model.Point in project amplify-android by aws-amplify.

the class TextractResultTransformers method fromPoints.

/**
 * Converts geometric polygon from Amazon Textract into
 * Amplify-compatible polygon object.
 * @param polygon the polygon object by Amazon Textract
 * @return the polygon object representing vertices
 */
@Nullable
public static Polygon fromPoints(@Nullable List<Point> polygon) {
    if (Empty.check(polygon)) {
        return null;
    }
    List<PointF> points = new ArrayList<>();
    for (Point point : polygon) {
        PointF androidPoint = new PointF(point.getX(), point.getY());
        points.add(androidPoint);
    }
    return Polygon.fromPoints(points);
}
Also used : PointF(android.graphics.PointF) ArrayList(java.util.ArrayList) Point(com.amazonaws.services.textract.model.Point) Nullable(androidx.annotation.Nullable)

Aggregations

Point (com.amazonaws.services.textract.model.Point)5 ArrayList (java.util.ArrayList)3 PointF (android.graphics.PointF)2 Nullable (androidx.annotation.Nullable)1 Polygon (com.amplifyframework.predictions.models.Polygon)1 Test (org.junit.Test)1