Skip to content

An example of implementing Liveness Detection and Identity OCR on android application using Kredibel-Vision-SDK.

Notifications You must be signed in to change notification settings

kredibel-id/VisionSample-Android

Repository files navigation

Vision Sample (Android)

gradle targetsdk ktx

↳ Stargazers

Stargazers repo roster for @kredibel-id/VisionSample-Android

↳ Forkers

Forkers repo roster for @kredibel-id/VisionSample-Android

↳ Share Please 😊

A sample project of implementing Liveness Detection and Identity OCR on Android app using Kredibel Vision SDK.

You can checkout the source code of this project.

git clone https://github.com/kredibel-id/VisionSample-Android.git

Then open this sample project with Android Studio or Intellij IDEA.







Vision SDK

Introduction

Vision SDK is a library that provides computer vision services such as Liveness Detection and Identity OCR with Kredibel VisionAI technology.

Features

Liveness Detection
  1. Examine the digital representation of the user's face from the camera preview in realtime.
  2. Out-of-frame face detection to prevent spoofing.
  3. Analyze multiple movements, including head movements, eye blinks, smiles and mouth opening to determine activity.
  4. Determine whether it is a living person or not.
Identity OCR

Identity OCR is an Optical Character Recognition (OCR) service that supports some types :

  1. National Identity (KTP)
  2. Driving License (SIM)
  3. Passport
  4. Handheld with Id Card selfie

Currently the Vision SDK can only be used on the Android platform.

Support API Level

minsdk targetsdk

Install / Setup

  • Aar file size : 2,7 MB

Gradle

1. Add kredibel repository.

repositories {
   ...
   ...
   maven{url 'https://repo.repsy.io/mvn/kredibel/sdk'} // <—-- add this 
}

2. Add this dependency to gradle script on app module.

dependencies {
    implementation 'io.kredibel:vision:0.0.1' // Please check latest version
    ...
    ...
}

API-Key

Please read the instructions here to get the API-Key or contact our sales team.

After getting API-Key then open your AndroidManifest.xml than add io.kredibel.sdk.APIKEY meta-data in the scope of <application></application> tag.

<meta-data android:name="io.kredibel.sdk.APIKEY" android:value="Your API-Key" /> 

How to Use (Basic Implementation)

The Vision class is the main class in the Kredibel Vision SDK. This class contains methods or functions to handle Liveness Detection and OCR quickly. You don't need to create a layout/UI, because we have provided everything. You just use all the functions/methods in the Vision class.

Liveness Detection

1. Single Detection

kotlin

Vision.with(this) // Context, required
    .detection(Detection.SMILE) // required
    .start()

java

Vision.with(this)
    .detection(Detection.SMILE) // required
    .start();

2. Multiple Detection

kotlin

Vision.with(this)
    .detection(arrayOf(Detection.SMILE, Detection.MOUTH_OPEN, Detection.BLINK_LEFT)) // required
    .delay(2000)  // milliseconds, optional. Default = 1000
    .start()

java

Vision.with(this)
    .detection(new String[]{Detection.SMILE, Detection.MOUTH_OPEN, Detection.BLINK_LEFT}) // required
    .delay(2000)  // milliseconds, optional. Default = 1000
    .start();

The following are some of the head and facial movements supported by the Vision SDK.

Face and Head Movements Parameters
Smile Detection.SMILE
Open mouth Detection.MOUTH_OPEN
Look Up Detection.LOOK_UP
Look to the right Detection.LOOK_RIGHT
Look down Detection.LOOK_DOWN
Look to the left Detection.LOOK_LEFT
Get random head and face movements Detection.RANDOM_HEAD_ANGLE
Left eye wink Detection.BLINK_LEFT
Right eye wink Detection.BLINK_RIGHT
Getting random winks Detection.RANDOM_EYE_BLINK

Identity OCR

kotlin

Vision.with(this)
    .identity(Identity.KTP)  // required. Identity type.
    .showOCRLastResult(true) // optional
    .onSuccessPage(SuccessPageActivity::class.java)  // optional
    .start()

java

Vision.with(this)
    .identity(Identity.KTP)  // required. Identity type.
    .showOCRLastResult(true) // optional
    .onSuccessPage(SuccessPageActivity.class)  // optional
    .start();

The following are some of the supported document types and their parameter names.

Dosument Type Parameters
Indonesian National Identity Card/ Kartu Tanda Penduduk(KTP) Identity.KTP
Driver's license Identity.SIM
Passport Identity.PASSPORT
Handheld with id card selfie Identity.HANDHELD

Get Result Data

You can use the onSuccessPage() method to select your activity that will receive the result data.

kotlin

Vision.with(this) // Context, required
    .detection(Detection.SMILE) // required
    .onSuccessPage(SuccessPageActivity::class.java) // optional for passing result data
    .start()

java

Vision.with(this)
    .detection(Detection.SMILE) // required
    .onSuccessPage(SuccessPageActivity.class) // optional for passing result data
    .start();

Then you can get result data from intent in your SuccessPageActivity on activity created override method with this parameters.

getParcelableArrayListExtra(Vision.RESULT_LIVENESS)

getParcelableExtra(Vision.RESULT_OCR)

Example :

kotlin

class SuccessPageActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_success_page)
        // get result data
        val livenessResults : List<LivenessResult> = intent.getParcelableArrayListExtra(Vision.RESULT_LIVENESS)!!
        val ocrResult : OcrResult = intent.getParcelableExtra(Vision.RESULT_OCR)!!
    }
}

java

public class SuccessPageActivity extends AppCompatActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);
        // get result data
        List<LivenessResult> livenessResults = getIntent().getParcelableArrayListExtra(Vision.RESULT_LIVENESS);
        OcrResult ocrResult = intent.getParcelableExtra(Vision.RESULT_OCR);
    }
}

Using VisionListener

You can use VisionListener for capture all detection results and or add a custom action after process.

If you use a VisionListener, then you don't need to call the onSuccessPage() method, because it won't run.

kotlin

Vision.with(this)
    .detection(arrayOf(Detection.SMILE, Detection.MOUTH_OPEN)) // required
    .listener(object : VisionListener{   // listener, optional on Liveness & OCR
        override fun onSuccess(livenessResult: MutableList<LivenessResult>?, ocrResult: OcrResult?) {
            // if you want to capture all detection results and or add a custom action.
        }

        override fun onError(s: String?) {
            showMessage(s!!)
        }
    })          
    .delay(2000)  // milliseconds, optional. Default = 1000
    .start()

java

Vision.with(this)
    .detection(new String[]{Detection.SMILE, Detection.MOUTH_OPEN}) // required
    .listener(new VisionListener() { // listener, optional on Liveness & OCR
        @Override
        public void onSuccess(List<LivenessResult> list, OcrResult ocrResult) {
            // if you want to capture all detection results and or add a custom action.
        }

        @Override
        public void onError(String s) {

        }
     })        
    .delay(2000)  // milliseconds, optional. Default = 1000
    .start();

Optional Features

Some optional features that you can use.

kotlin

Vision.with(this)
    .debug() // If you want to run in debug mode for development purposes use Sandbox API : https://synapses.sandbox.kredibel.co.id/"  
    .detection(arrayOf(Detection.SMILE, Detection.MOUTH_OPEN)) // required
    .delay(2000)  // milliseconds, optional. Default = 1000
    .onSuccessPage(SecondActivity::class.java) // optional
    .finishOnSuccess(true) // optional, for auto destroy current activity/context after liveness/ocr process.
    .showContour(true)     // optional
    .showLabel(true)       // optional
    .showBoundingBox(true) // optional
    .start()

java

Vision.with(this)
    .debug() // If you want to run in debug mode for development purposes use Sandbox API : https://synapses.sandbox.kredibel.co.id/"
    .detection(new String[]{Detection.SMILE, Detection.MOUTH_OPEN}) // required  
    .delay(2000)  // milliseconds, optional. Default = 1000
    .onSuccessPage(SecondActivity.class) // optional
    .finishOnSuccess(true) // optional, for auto destroy current activity/context after liveness/ocr process.
    .showContour(true)     // optional
    .showLabel(true)       // optional
    .showBoundingBox(true) // optional
    .start();

Customizing String

You can customize instructions and some text by adding the following string resource to your project. Add only the strings you need and make sure the string name is correct, don't be mistaken.

<!--Vision General-->
<string name="kv_title_close" translatable="false">Close</string>
<string name="kv_title_next" translatable="false">Next</string>
<string name="kv_msg_loading_data" translatable="false">Loading...</string>

<!--Vision Liveness-->
<string name="kv_title_instruction" translatable="false">Follow instruction:</string>
<string name="kv_title_liveness" translatable="false">Liveness Detection</string>
<string name="kv_title_identity_type" translatable="false">Identity Type</string>
<string name="kv_msg_verification_complete" translatable="false">Verification Complete</string>

<!--Before detection-->
<string name="kv_clue_yourface_inframe" translatable="false">Make sure your face is in the frame and in a well-lit place.
</string>

<!--After detection, then face out of circle.-->
<string name="kv_msg_yourface_out_circle" translatable="false">Oops! Your face should stay in circle during liveness. We will try again from the beginning.</string>
<string name="kv_msg_liveness_oncomplete" translatable="false">You have successfully followed all instructions, congrats!
</string>

<!-- Face orientation-->
<string name="kv_smile" translatable="false">Please Smile</string>
<string name="kv_left_eye_blink" translatable="false">Left Eye Blink</string>
<string name="kv_right_eye_blink" translatable="false">Right Eye Blink</string>
<string name="kv_look_up" translatable="false">Look Up</string>
<string name="kv_look_down" translatable="false">Look Down</string>
<string name="kv_look_left" translatable="false">Look Left</string>
<string name="kv_look_right" translatable="false">Look Right</string>
<string name="kv_open_mouth" translatable="false">Open your Mouth</string>

<!-- Vision Identity OCR-->
<string name="kv_title_ocr_last_result" translatable="false">See Last Result</string>
<string name="kv_title_identity_result" translatable="false">Identity Result</string>
<string name="kv_title_scan_identity" translatable="false">Scan Identity</string>
<string name="kv_title_scan_ktp" translatable="false">Scan Identity - KTP</string>
<string name="kv_title_scan_sim" translatable="false">Scan Identity - SIM</string>
<string name="kv_title_scan_passport" translatable="false">Scan Identity - PASSPORT</string>
<string name="kv_title_hand_held" translatable="false">Selfie holding Identity card</string>
<string name="kv_title_ocr_start" translatable="false">Start Verification</string>
<string name="kv_title_ocr_take_picture" translatable="false">Take Picture</string>
<string name="kv_title_ocr_uploading" translatable="false">Uploading...</string>
<string name="kv_msg_upload_identity" translatable="false">Uploading Identity ...</string>
<string name="kv_msg_ocr_succeded" translatable="false">Verification succeeded</string>
<string name="kv_msg_ocr_see_result" translatable="false">Click the "See Last Result" button to see your verification livenessResult.</string>
<string name="kv_msg_upload" translatable="false">Your identity is being uploaded and processed by our system, it may take some time.</string>
<string name="kv_msg_ocr_verification_failed" translatable="false">Verification Failed</string>
<string name="kv_clue_card_inframe" translatable="false">Position your identity card in the frame and in a well-lit place.
</string>