Skip to content

Latest commit

 

History

History
270 lines (211 loc) · 7.48 KB

Advance.md

File metadata and controls

270 lines (211 loc) · 7.48 KB

Advance Implementation : Create Own Vision Activity.

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.

Create new Activity, then extends from VisionActivity.

kotlin

class CustomLivenessActivity : VisionActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_custom_liveness)
    }
}

java
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);
    }
}

Using LivenessCameraView Component

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"/>

Initialize

kotlin

val livenessView : LivenessCameraView = findViewById(R.id.livenessView)

java

LivenessCameraView livenessView = findViewById(R.id.livenessView);

Detection

kotlin

livenessView.setDetections(arrayOf(Detection.SMILE, Detection.MOUTH_OPEN, Detection.BLINK_LEFT))

java

livenessView.setDetections(new String[]{Detection.SMILE, Detection.MOUTH_OPEN, Detection.BLINK_LEFT});

LivenessDetectionListener

LivenessDetectionListener is a java interface that will accommodate the results of the liveness detection process.

kotlin

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)

java

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);

Start Preview

To start preview and Liveness Detection process, you can call the start() method.

kotlin

livenessView.start()

java

livenessView.start();

Stop Preview

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().

kotlin

livenessView.stop()

java

livenessView.stop();

Using OCRCameraView Component

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"/>

Initialize

kotlin

val ocrPreview : OCRCameraPreview = findViewById(R.id.ocrPreview)

java

OCRCameraPreview ocrPreview = findViewById(R.id.ocrPreview);

Start Preview

kotlin

ocrPreview.start()

java

ocrPreview.start();

OCRCameraListener

OCRCameraListener is a java interface that will accommodate the results of the Identity OCR process.

kotlin

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?) {
            
    }
}

java

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

Take identity and start OCR Process.

kotlin

ocrPreview.takeIdentity(Identity.KTP, listener)

java

ocrPreview.takeIdentity(Identity.KTP, listener);

Stop Preview

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().

kotlin

ocrPreview.stop()

java

ocrPreview.stop();