Implementation¶
PreviewView¶
If you need to present a preview to a user, you need to initiate a PreviewView
in an Activity/Fragment's layout.
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent">
<androidx.camera.view.PreviewView
android:id="@+id/previewView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
DefaultDocumentDetector¶
A document recognizer that detects a document.
Create a DefaultDocumentDetector
instance in the onCreate
of your Activity
and close it in onDestroy
.
override fun onCreate() {
onDocumentQualityCheckResultListener = OnDocumentQualityCheckResultListener { result ->
// Show a hint to user about the conditions
}
documentDetector = DefaultDocumentDetector(onDocumentQualityCheckResultListener)
}
override fun onDestroy() {
documentDetector.close()
}
You don't need to use it in a straightforward way. The right way is to use its functionality through the DocumentIadCameraController
API.
DocumentQualityStatus¶
During a document recognition you may receive a next descriptions of document recognition work.
/**
* Document quality status.
*/
enum class DocumentQualityStatus {
/**
* Document is OK.
*/
OK,
/**
* Document border(s) are outside the frame.
*/
DocumentBordersOutsideOfFrame,
/**
* Document border(s) are outside the frame.
*/
DocumentNotFound,
/**
* Document is too close to the frame border.
*/
DocumentTooCloseToBorder,
/**
* More than one document are present in the frame.
*/
MultipleDocumentsInFrame,
/**
* Document size (area) is lower than 10% of the frame size.
*/
RelativeDocumentSizeLowerThen10Percent
}
DocumentIadCameraController¶
A class that provides an API for camera control.
Create an instance with:
PreviewView
: a view from theCameraX
package that implements a preview featureDefaultDocumentDetector
: the document detectorlifecycleOwner
: typically an instance of anActivity
Take into consideration that
DocumentIadCameraController
cannot run concurrently, meaning that only one instance can run at any given time.
Instantiate it in the onCreate
of your Activity
and close it in the onDestroy
method.
override fun onCreate() {
cameraController = DocumentIadCameraController(documentDetector, peviewView, lifecycleOwner)
}
override fun onDestroy() {
cameraController.close()
}
Connect the lifecycle of DocumentIadCameraController
with the lifecycle of Activity
.
override fun onStart() {
cameraController.openCamera()
}
override fun onStop() {
cameraController.closeCamera()
}
Add data processors to DocumentIadCameraController
.
cameraController.onCameraErrorListener = OnCameraErrorListener { error ->
// Handle the exception.
}
cameraController.onDetectionErrorListener = OnDetectionErrorListener { exception ->
// Handle the exception.
}
cameraController.photoProcessor = object : ImageProcessor {
override fun process(data: ByteArray, size: Size, format: Int, rotationAngle: Int) {
// Photo processing: You can display the photo as a preview for the user.
// Additionally, this event is an appropriate time to show a progress bar.
}
}
cameraController.bundleProcessor = object : BundleProcessor {
override fun process(bundle: ByteArray) {
// Pass this bundle to IDLiveDoc Plus server for processing.
// The server returns an injection attack probability.
}
}
Call takePhoto()
if you need a photo immediately without the condition check.
cameraController.takePhoto()
Example¶
Additional information on how to use the library can be found in the folder within the release archive at the path idlive-doc-capture-android-X.X.X-release/iad-withDocumentDetector-example
.