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 is a library that provides computer vision services such as Liveness Detection and Identity OCR with Kredibel VisionAI technology.
- Examine the digital representation of the user's face from the camera preview in realtime.
- Out-of-frame face detection to prevent spoofing.
- Analyze multiple movements, including head movements, eye blinks, smiles and mouth opening to determine activity.
- Determine whether it is a living person or not.
Identity OCR is an Optical Character Recognition (OCR) service that supports some types :
- National Identity (KTP)
- Driving License (SIM)
- Passport
- Handheld with Id Card selfie
Currently the Vision SDK can only be used on the Android platform.
- Aar file size : 2,7 MB
repositories {
...
...
maven{url 'https://repo.repsy.io/mvn/kredibel/sdk'} // <—-- add this
}
dependencies {
implementation 'io.kredibel:vision:0.0.1' // Please check latest version
...
...
}
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" />
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.
Vision.with(this) // Context, required
.detection(Detection.SMILE) // required
.start()
Vision.with(this)
.detection(Detection.SMILE) // required
.start();
Vision.with(this)
.detection(arrayOf(Detection.SMILE, Detection.MOUTH_OPEN, Detection.BLINK_LEFT)) // required
.delay(2000) // milliseconds, optional. Default = 1000
.start()
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 |
Vision.with(this)
.identity(Identity.KTP) // required. Identity type.
.showOCRLastResult(true) // optional
.onSuccessPage(SuccessPageActivity::class.java) // optional
.start()
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 |
You can use the onSuccessPage() method to select your activity that will receive the result data.
Vision.with(this) // Context, required
.detection(Detection.SMILE) // required
.onSuccessPage(SuccessPageActivity::class.java) // optional for passing result data
.start()
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 :
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)!!
}
}
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);
}
}
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.
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()
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();
Some optional features that you can use.
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()
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();
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>