DOT Android Document 3.0.0
This guide describes how to migrate DOT Android Document version 2.x to version 3.0.0. Only the most important changes are highlighted in this guide. For more details, see the Android sample.
Migration Steps
Update build.gradle
file
Set minSdkVersion
to 21
or higher.
Change the dependency to the DOT Android Document:
dependencies {
implementation 'com.innovatrics.dot:dot-document:3.0.0'
}
DocumentDetector
component
- Replace
DefaultDocumentDetector.Builder
withDocumentDetectorFactory
. - Replace
DetectionResult
withDocumentDetector.Result
.
Before
DocumentDetector documentDetector = new DefaultDocumentDetector.Builder().build();
DetectionResult result = documentDetector.detect(bgraRawImage);
After
DocumentDetector documentDetector = DocumentDetectorFactory.create();
DocumentDetector.Result result = documentDetector.detect(bgraRawImage);
ImageParametersAnalyzer
component
- Replace
DefaultImageParametersAnalyzer.Builder
withImageParametersAnalyzerFactory
.
Before
ImageParametersAnalyzer imageParametersAnalyzer = new DefaultImageParametersAnalyzer.Builder().build();
After
ImageParametersAnalyzer imageParametersAnalyzer = ImageParametersAnalyzerFactory.create();
DocumentAutoCaptureController
component
- Remove
DocumentAutoCaptureFrameParametersEvaluator
callback. - Replace
DefaultDocumentAutoCaptureController.Builder
withDocumentAutoCaptureControllerConfiguration
andDocumentAutoCaptureControllerFactory
. - Replace
detect()
method withprocess()
method.
Before
DocumentAutoCaptureFrameParametersEvaluator documentAutoCaptureFrameParametersEvaluator = new PlaceholderEvaluatorFactory.Builder(placeholderFrame)
.build()
.create();
DocumentAutoCaptureController documentAutoCaptureController = new DefaultDocumentAutoCaptureController.Builder()
.documentAutoCaptureFrameParametersEvaluator(documentAutoCaptureFrameParametersEvaluator)
.detectionFrame(detectionFrame)
.imageParametersFrame(imageParametersFrame)
.onDetectionListener(this::handleDetection)
.onStayStillPhaseEnterListener(this::handleStayStillPhaseEnter)
.onCaptureListener(this::handleCapture)
.build();
...
documentAutoCaptureController.detect(nv21Image);
After
DocumentAutoCaptureControllerConfiguration configuration = new DocumentAutoCaptureControllerConfiguration.Builder(context, validators)
.detectionNormalizedRectangle(detectionNormalizedRectangle)
.imageParametersNormalizedRectangle(imageParametersNormalizedRectangle)
.onDetectionListener(this::handleDetection)
.onCandidateSelectionStartListener(this::handleCandidateSelectionStart)
.onCaptureListener(this::handleCapture)
.build();
DocumentAutoCaptureController documentAutoCaptureController = DocumentAutoCaptureControllerFactory.create(configuration);
...
documentAutoCaptureController.process(bgraRawImage);
Document Auto Capture Fragment
- Remove
onCameraInitFailed()
callback. - Remove
onCameraAccessFailed()
callback. - Remove
onAutoCaptureReady()
callback. If you want to start the process as soon as possible callstart()
method inonCreate()
callback. - Replace
onPhotoCaptured()
callback withonCaptured()
callback.
Create Document Auto Capture Fragment
instance
- Replace configuration DTO
DocumentAutoCaptureArguments
withDocumentAutoCaptureConfiguration
. - Replace bundle key
DocumentAutoCaptureFragment.ARGUMENTS
withDocumentAutoCaptureFragment.CONFIGURATION
.
Before
DocumentAutoCaptureArguments documentAutoCaptureArguments = new DocumentAutoCaptureArguments.Builder().build();
Bundle arguments = new Bundle();
arguments.putSerializable(DocumentAutoCaptureFragment.ARGUMENTS, documentAutoCaptureArguments);
Fragment fragment = new DemoDocumentAutoCaptureFragment();
fragment.setArguments(arguments);
After
DocumentAutoCaptureConfiguration documentAutoCaptureConfiguration = new DocumentAutoCaptureConfiguration.Builder().build();
Bundle arguments = new Bundle();
arguments.putSerializable(DocumentAutoCaptureFragment.CONFIGURATION, documentAutoCaptureConfiguration);
Fragment fragment = new DemoDocumentAutoCaptureFragment();
fragment.setArguments(arguments);
Image Conversion
New DOT Document API uses BgraRawImage
DTO as an image representation.
Create BgraRawImage
from Bitmap
:
BgraRawImage bgraRawImage = BgraRawImageFactory.create(bitmap);
Create BgraRawImage
from Nv21Image
(Android Camera API):
BgraRawImage bgraRawImage = BgraRawImageFactory.create(nv21Image);
Create BgraRawImage
from ImageProxy
/ YUV_420_888 (Android CameraX API):
BgraRawImage bgraRawImage = BgraRawImageFactory.create(yuv420Image);
Create Bitmap
from BgraRawImage
:
Bitmap bitmap = BitmapFactory.create(bgraRawImage);