public final class DocumentScanner

  1. Object
  2. DocumentScanner

ImplementsAutoCloseable, VisionAnalyzer<DocumentScanResult>

Finds a page in a photo and returns it flattened, with the perspective corrected.

DocumentScanner scanner = new DocumentScanner();
if (!scanner.isSupported()) {
    // Android's document scanner is an interactive Google flow rather than
    // an analyzer, so this reports unsupported there.
    scanner.close();
    return;
}
scanner.process(VisionImage.fromFile(photoPath)).ready(result -> {
    for (int i = 0; i < result.getPageCount(); i++) {
        pages.add(EncodedImage.create(result.getPage(i)));
    }
    scanner.close();
}).except(error -> {
    Log.e(error);
    scanner.close();
});

This is a still-image analyzer: capture the photo however you like – the Capture API, a CameraSession, or the gallery – and hand the bytes over.

Constructors

public DocumentScanner()Creates an analyzer using the platform default backend and options.
public DocumentScanner(VisionOptions options)Creates a reusable analyzer with explicit backend and result options.

Methods

public final synchronized boolean isSupported()Tests the exact feature/backend pair configured for this analyzer.
public final synchronized AsyncResource<DocumentScanResult> process(VisionImage image)Starts one analysis using the retained native backend.
public final synchronized void close()Idempotently releases the retained native backend.

Inherited methods

Constructor details

DocumentScanner

public DocumentScanner()
Creates an analyzer using the platform default backend and options.

DocumentScanner

public DocumentScanner(VisionOptions options)
Creates a reusable analyzer with explicit backend and result options.

Parameters

options VisionOptions
configuration captured by this analyzer; null uses defaults

Method details

isSupported

public final synchronized boolean isSupported()
Tests the exact feature/backend pair configured for this analyzer.

Returns

whether this analyzer’s feature/backend is available and open

process

public final synchronized AsyncResource<DocumentScanResult> process(VisionImage image)
Starts one analysis using the retained native backend.

Parameters

image VisionImage
immutable encoded or raw input

Returns

asynchronous typed result

close

public final synchronized void close()
Idempotently releases the retained native backend.