use of com.amplifyframework.predictions.result.IdentifyDocumentTextResult in project amplify-android by aws-amplify.
the class AWSPredictionsIdentifyTextTest method testIdentifyTables.
/**
* Assert table detection works.
* @throws PredictionsException if prediction fails
*/
@Test
public void testIdentifyTables() throws PredictionsException {
final Bitmap image = Assets.readAsBitmap("sample-table.png");
// Identify the text inside given image and assert non-null result.
IdentifyDocumentTextResult result = (IdentifyDocumentTextResult) predictions.identify(TextFormatType.TABLE, image);
assertNotNull(result);
// Assert that one table is detected.
List<Table> tables = result.getTables();
assertFalse(Empty.check(tables));
assertEquals(1, tables.size());
// Assert that table has correct dimensions.
Table table = tables.get(0);
assertEquals(2, table.getRowSize());
assertEquals(2, table.getColumnSize());
// Assert that table has correct cells.
List<Cell> cells = table.getCells();
assertEquals(4, cells.size());
FeatureAssert.assertContains("Name", cells);
FeatureAssert.assertContains("Address", cells);
FeatureAssert.assertContains("Ana Carolina", cells);
FeatureAssert.assertContains("123 Any Town", cells);
}
use of com.amplifyframework.predictions.result.IdentifyDocumentTextResult in project amplify-android by aws-amplify.
the class AWSPredictionsIdentifyTextTest method testIdentifyForms.
/**
* Assert form detection works.
* @throws PredictionsException if prediction fails
*/
@Test
public void testIdentifyForms() throws PredictionsException {
final Bitmap image = Assets.readAsBitmap("sample-form.png");
// Identify the text inside given image and assert non-null result.
IdentifyDocumentTextResult result = (IdentifyDocumentTextResult) predictions.identify(TextFormatType.FORM, image);
// Assert that four key-values are detected.
List<BoundedKeyValue> keyValues = result.getKeyValues();
assertFalse(Empty.check(keyValues));
assertEquals(4, keyValues.size());
// Assert that key-value pairs have correct values.
FeatureAssert.assertContains(Pair.create("Name:", "Jane Doe"), keyValues);
FeatureAssert.assertContains(Pair.create("Address:", "123 Any Street, Anytown, USA"), keyValues);
FeatureAssert.assertContains(Pair.create("Birth date:", "12-26-1980"), keyValues);
// FeatureAssert.assertContains(Pair.create("Male:", "true"), keyValues); // Selection not supported
}
use of com.amplifyframework.predictions.result.IdentifyDocumentTextResult in project amplify-android by aws-amplify.
the class RxPredictionsBindingTest method testSuccessfulImageIdentification.
/**
* When the delegate of {@link RxPredictionsBinding#identify(IdentifyAction, Bitmap)} succeeds,
* the result should be propagated via the returned {@link Single}.
* @throws InterruptedException If interrupted while test observer is awaiting terminal event
*/
@Test
public void testSuccessfulImageIdentification() throws InterruptedException {
Bitmap bitmap = Bitmap.createBitmap(10, 10, Bitmap.Config.ALPHA_8);
IdentifyDocumentTextResult result = IdentifyDocumentTextResult.builder().fullText(RandomString.string()).keyValues(Collections.emptyList()).lines(Collections.emptyList()).rawLineText(Collections.emptyList()).selections(Collections.emptyList()).tables(Collections.emptyList()).words(Collections.emptyList()).build();
doAnswer(invocation -> {
// 0 = type, 1 = bitmap, 2 = result, 3 = error
final int indexOfResultConsumer = 2;
Consumer<IdentifyDocumentTextResult> onResult = invocation.getArgument(indexOfResultConsumer);
onResult.accept(result);
return mock(IdentifyOperation.class);
}).when(delegate).identify(eq(IdentifyActionType.DETECT_TEXT), eq(bitmap), anyConsumer(), anyConsumer());
TestObserver<IdentifyResult> observer = rxPredictions.identify(IdentifyActionType.DETECT_TEXT, bitmap).test();
observer.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
observer.assertValue(result);
}
Aggregations