In the basic implementation, you have understood the use of the start() method in the Vision class. Really, it's the quick and easy way.
At an advanced level, you can create your own Liveness Detection Activity or OCR Activity with your own UI Design.
class CustomLivenessActivity : VisionActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_custom_liveness)
}
}
In Java, you must change Access Modifiers of onCreate method from protected to public.
public class CustomLivenessActivity extends VisionActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_ocr);
}
}
LivenessCameraPreview is a component which is a SurfaceView which includes a Camera controller and a Liveness Detection Processor with Machine Learning. This component can display the camera preview and process liveness detection at the same time.
Add this component to your activity or fragment layout page. Well, here you can design your own UI/UX.
<io.kredibel.vision.LivenessCameraView
android:id="@+id/livenessView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:foregroundGravity="center"/>
val livenessView : LivenessCameraView = findViewById(R.id.livenessView)
LivenessCameraView livenessView = findViewById(R.id.livenessView);
livenessView.setDetections(arrayOf(Detection.SMILE, Detection.MOUTH_OPEN, Detection.BLINK_LEFT))
livenessView.setDetections(new String[]{Detection.SMILE, Detection.MOUTH_OPEN, Detection.BLINK_LEFT});
LivenessDetectionListener is a java interface that will accommodate the results of the liveness detection process.
val listener = object : LivenessDetectionListener {
override fun onError(message: String?) {
// Getting an error message if the process failed.
}
override fun onPrepare(isLoading: Boolean) {
// Get process preparation status.
}
override fun onDetecting(isDetection: Boolean, detection: String?) {
// get detection status
}
override fun onEachCompleted(livenessResult: LivenessResult?) {
// Get results on each detection.
}
override fun onAllCompleted(livenessResults: MutableList<LivenessResult>?) {
// Get all detection results.
}
}
livenessView.setLivenessDetectionListener(listener)
LivenessDetectionListener listener = new LivenessDetectionListener() {
@Override
public void onError(String message) {
// Getting an error message if the process failed.
}
@Override
public void onPrepare(boolean isLoading) {
// Get process preparation status.
}
@Override
public void onDetecting(boolean isDetecting, String detection) {
// get detection status
}
@Override
public void onEachCompleted(LivenessResult livenessResult) {
// Get results on each detection.
}
@Override
public void onAllCompleted(List<LivenessResult> livenessResults) {
// Get all detection results.
}
};
livenessView.setLivenessDetectionListener(listener);
To start preview and Liveness Detection process, you can call the start() method.
livenessView.start()
livenessView.start();
Don't forget to stop the process when it's finished or not in use. You can call it on onDestroy() on the Activity or on finish().
livenessView.stop()
livenessView.stop();
OCRCameraView is a component which is a SurfaceView which includes a Camera controller and a OCR with Kredibel API.
<io.kredibel.vision.OCRCameraView
android:id="@+id/ocrPreview"
android:layout_width="match_parent"
android:layout_height="600dp"
android:layout_alignParentTop="true"/>
val ocrPreview : OCRCameraPreview = findViewById(R.id.ocrPreview)
OCRCameraPreview ocrPreview = findViewById(R.id.ocrPreview);
ocrPreview.start()
ocrPreview.start();
OCRCameraListener is a java interface that will accommodate the results of the Identity OCR process.
val listener = object : OCRCameraListener{
override fun onGetBitmap(bitmap: Bitmap?) {
}
override fun onError(message: String?) {
}
override fun onProgress(isLoading: Boolean) {
}
override fun onComplete(isVerified: Boolean, ocrResult: OcrResult?) {
}
}
OCRCameraListener listener = new OCRCameraListener() {
@Override
public void onGetBitmap(Bitmap bitmap) {
// Getting photo as Bitmap.
}
@Override
public void onError(String onError) {
//Getting an error message if the process failed.
}
@Override
public void onProgress(boolean isShow) {
// get process status
}
@Override
public void onComplete(boolean isSuccess, JSONObject response) {
// When OCR process is completed
}
};
Take identity and start OCR Process.
ocrPreview.takeIdentity(Identity.KTP, listener)
ocrPreview.takeIdentity(Identity.KTP, listener);
Don't forget to stop the process when it's finished or not in use. You can call it on onDestroy() on the Activity or on finish().
ocrPreview.stop()
ocrPreview.stop();