use of com.amazonaws.services.textract.model.Block in project aws-doc-sdk-examples by awsdocs.
the class DocumentText method paintComponent.
// Draws the image and text bounding box.
public void paintComponent(Graphics g) {
int height = image.getHeight(this);
int width = image.getWidth(this);
// Create a Java2D version of g.
Graphics2D g2d = (Graphics2D) g;
// Draw the image.
g2d.drawImage(image, 0, 0, image.getWidth(this), image.getHeight(this), this);
// Iterate through blocks and display polygons around lines of detected text.
List<Block> blocks = result.getBlocks();
for (Block block : blocks) {
DisplayBlockInfo(block);
if ((block.getBlockType()).equals("LINE")) {
ShowPolygon(height, width, block.getGeometry().getPolygon(), g2d);
/*
ShowBoundingBox(height, width, block.getGeometry().getBoundingBox(), g2d);
*/
} else {
// its a word, so just show vertical lines.
ShowPolygonVerticals(height, width, block.getGeometry().getPolygon(), g2d);
}
}
}
use of com.amazonaws.services.textract.model.Block in project amplify-android by aws-amplify.
the class TextractResultTransformers method doForEachRelatedBlock.
private static void doForEachRelatedBlock(Block block, Map<String, Block> blockMap, Consumer<Block> forEach) {
if (block == null || block.getRelationships() == null) {
return;
}
for (Relationship relationship : block.getRelationships()) {
for (String id : relationship.getIds()) {
Block relatedBlock = blockMap.get(id);
if (relatedBlock == null) {
continue;
}
forEach.accept(relatedBlock);
}
}
}
use of com.amazonaws.services.textract.model.Block in project amplify-android by aws-amplify.
the class TextractResultTransformersTest method testIdentifiedTextConversion.
/**
* Tests that the individual block from Textract is converted to
* an Amplify image text feature.
*/
@Test
public void testIdentifiedTextConversion() {
Block block = new Block().withText(RandomString.string()).withConfidence(random.nextFloat()).withGeometry(randomGeometry()).withPage(random.nextInt());
// Test block conversion
IdentifiedText text = TextractResultTransformers.fetchIdentifiedText(block);
assertEquals(block.getText(), text.getText());
assertEquals(block.getConfidence(), text.getConfidence(), DELTA);
assertEquals((int) block.getPage(), text.getPage());
}
use of com.amazonaws.services.textract.model.Block in project amplify-android by aws-amplify.
the class TextractResultTransformersTest method testSelectionConversion.
/**
* Tests that the individual block from Textract is properly
* converted to an Amplify selection item.
*/
@Test
public void testSelectionConversion() {
Block block;
Selection selection;
// Assert that SELECTED sets it to selected
block = new Block().withSelectionStatus(SelectionStatus.SELECTED).withGeometry(randomGeometry());
selection = TextractResultTransformers.fetchSelection(block);
assertTrue(selection.isSelected());
// Assert that NOT_SELECTED sets it to not selected
block = new Block().withSelectionStatus(SelectionStatus.NOT_SELECTED).withGeometry(randomGeometry());
selection = TextractResultTransformers.fetchSelection(block);
assertFalse(selection.isSelected());
}
use of com.amazonaws.services.textract.model.Block in project amplify-android by aws-amplify.
the class TextractResultTransformersTest method testTableConversion.
/**
* Tests that the graph of related blocks from Textract is properly
* converted to an Amplify table item.
*/
@Test
public void testTableConversion() {
Block cellTextBlock = new Block().withId(RandomString.string()).withText(RandomString.string());
Block cellSelectionBlock = new Block().withId(RandomString.string()).withSelectionStatus(SelectionStatus.SELECTED);
Block cellBlock = new Block().withId(RandomString.string()).withBlockType(BlockType.CELL).withConfidence(random.nextFloat()).withGeometry(randomGeometry()).withRowIndex(random.nextInt()).withColumnIndex(random.nextInt()).withRelationships(new Relationship().withIds(cellTextBlock.getId(), cellSelectionBlock.getId()));
Block tableBlock = new Block().withId(RandomString.string()).withBlockType(BlockType.TABLE).withConfidence(random.nextFloat()).withGeometry(randomGeometry()).withRelationships(new Relationship().withIds(cellBlock.getId()));
// Construct a map to act as a graph
Map<String, Block> blockMap = new HashMap<>();
Observable.fromArray(cellTextBlock, cellSelectionBlock, cellBlock, tableBlock).blockingForEach(block -> blockMap.put(block.getId(), block));
// Test table block conversion
Table table = TextractResultTransformers.fetchTable(tableBlock, blockMap);
assertEquals(1, table.getCells().size());
assertEquals(tableBlock.getConfidence(), table.getConfidence(), DELTA);
assertEquals(1, table.getRowSize());
assertEquals(1, table.getColumnSize());
// Test cell block conversion
Cell cell = table.getCells().iterator().next();
assertEquals(cellTextBlock.getText(), cell.getText());
assertEquals(cellBlock.getConfidence(), cell.getConfidence(), DELTA);
assertTrue(cell.isSelected());
assertEquals(cellBlock.getRowIndex() - 1, cell.getRow());
assertEquals(cellBlock.getColumnIndex() - 1, cell.getColumn());
}
Aggregations