TrustVision SDK is an android SDK for TrustVision Engine. It provides these features:
Add google services json file to project
Add key to info.plist:
<key>NSCameraUsageDescription</key>
<string>Open camera</string>
To initialize the SDK, add the following line to your app before calling any other SDK . For example, you can add it to the viewDidLoad
method of the application class.
override func viewDidLoad() {
super.viewDidLoad()
TrustVisionSdk.initialize(
accessKeyId: accessKey,
accessKeySecret: secretKey,
isForced: false,
success: {
}, failure: { (error) in
})
}
After the SDK is initalized, use this method to get list supported ID.
do {
let cardTypes: [TSCardType] = try TrustVisionSdk.getCardTypes()
} catch error {
}
Start transaction should be called when start new user journey.
TrustVisionSdk.startTransaction(
referenceID: referenceID,
success: { (transactionId) in
}, failure: { (error) in
})
where:
The SDK provides some built in Activities example activity to capture id, selfie, liveness...
let config = TVSDKConfig.defaultConfig()
Options:
TVCardType
. List of supported cards can be found by let cardTypes: [TSCardType] = try TrustVisionSdk.getCardTypes()
ActionMode
. Action modeTVLivenessMode
. Liveness modeBool
. Sound should be played or notBool
. Check id card sanity or notBool
. Check id card sanity or notBool
. Check id card tampering or notTVCameraOption
. Camera modelet vc = try TrustVisionSdk.newCameraViewController(config: config) { (result, error) in
print("[SDK result] \(String(describing: result?.description))")
}
self.present(vc, animated: true, completion: nil)
where:
TVSDKConfig
TVDetectionResult
. Use all fieldsFailureCallback
CancellationCallback
The id capturing activity will show the camera to capture image, preview the image, upload image and then do OCR. To start the id capturing activity.
let config: TVIdCardConfiguration = TVIdCardConfig()
config.idCardSide = TVCardSide.front
config.cardType = selectedCardType
confg.isEnableSound = false
Options:
TVCardType
. List of supported cards can be found by let cardTypes: [TSCardType] = try TrustVisionSdk.getCardTypes()
TVCardSide
. Card side to captureBool
. Sound should be played or notBool
. Check id card sanity or notBool
. If true then the sdk will capture both side if possible; otherwise, then the card side defined in cardSide will be usedBool
. Check id card tampering or notlet vc = TrustVisionSdk.startIdCapturing(configuration: config, success: { (result) in
}, failure: { (error) in
}, cancellation: {
// sdk is canceled
})
where:
TVIdCardConfiguration
TVDetectionResult
. Use the following fields:FailureCallback
CancellationCallback
The selfie capturing activity will show the camera to capture image, preview the image, upload image, verify sanity (blurry, too bright, too dark, not white background...), and verify liveness. To start the selfie capturing activity.
let config: TVSelfieConfiguration = TVSelfieConfiguration()
config.cameraOption = TVCameraOption.front
confg.isEnableSound = false
config.isSanityRequired = true
config.livenessMode = TVLivenessMode.passive
Options:
TVCameraOption
.TVLivenessMode
let vc = TrustVisionSdk.startSelfieCapturing(configuration: config, success: { (result) in
}, failure: { (error) in
}, cancellation: {
// sdk is canceled
})
where:
configuration: TVSelfieConfiguration
success method that will be called in case success. Parameters:
result : TVDetectionResult
. Use the following fields:
failure: FailureCallback
cancellation: CancellationCallback
The face matching does not need an hosted activity, the SDK will send an asynchronous request to server and send back the face-matching response
Send face-matching request
TrustVisionSDK.matchFace(imageId1, imageId2, success: { (result) in
}, failure: { (error) in
})
where:
success
method has one parameter.TVCompareFacesResult
FailureCallback
// [FlowStartingFunc]: newCameraViewController, startIdCapturing
let vc = TrustVisionSdk.[FlowStartingFunc](configuration: config, success: { (result) in
if let sanityError = result.idSanityResult?.error {
switch sanityError.errorCode {
case "image_too_blur":
// Image is too blurry
case "image_too_dark":
// Image is too dark
case "image_too_bright":
// Image is too bright
case "image_has_hole":
// Image has holes
case "image_has_cut":
// Images has been cut
case "image_has_hole_and_cut":
// Images has holes and has been cut
}
}
}, failure: { (error) in
// errors
}, cancellation: {
// sdk is canceled
})
// [FlowStartingFunc]: newCameraViewController, startSelfieCapturing
let vc = TrustVisionSdk.[FlowStartingFunc](configuration: config, success: { (result) in
if let sanityError = result.selfieSanityResult?.error {
switch sanityError.errorCode {
case "image_too_blur":
// Image is too blurry
case "image_too_dark":
// Image is too dark
case "image_too_bright":
// Image is too bright
case "not_white_background":
// The background is not white enough
case "not_qualified":
// The face is not qualified, could be occluded, covered or having something unusal
case "image_has_multiple_faces":
// Image has multiple faces
case "image_has_no_faces":
// Image does not have any face
case "right":
// Face is looking to the right
case "left":
// Face is looking to the left
case "open_eye,closed_eye":
// Right eye is closed
case "closed_eye,open_eye":
// Left eye is closed
case "open_eye,sunglasses":
// Sunglass covers the right eye
case "sunglasses,open_eye":
// Sunglass covers the left eye
case "closed_eye,closed_eye":
// Both eyes are closed
case "closed_eye,sunglasses":
// Left eye is closed, sunglass covers the right eye
case "sunglasses,closed_eye":
// Sunglass covers the right eye, right eye is closed
case "sunglasses,sunglasses":
// Sunglasses cover both eyes
}
}
}, failure: { (error) in
// errors
}, cancellation: {
// sdk is canceled
})
// [FlowStartingFunc]: newCameraViewController, startIdCapturing, startSelfieCapturing, matchFace
let vc = TrustVisionSdk.[FLowStartingFunc](configuration: config, success: { (result) in
// result
}, failure: { (error) in
switch error.errorCode {
// pre-defined errors
case "authentication_missing_error",
"network_error",
"internal_error",
"timeout_error":
// server errors
default:
switch error.errorCode {
// Id capturing errors
case "incorrect_card_type":
// the input image is not same type with selected card
case "nocard_or_multicard_image":
// the input image is no card or multicard detected
// Selfie capturing and faces matching errors
case "image_has_no_faces":
// face not detected in selfie image
case "image_has_multipe_faces":
// multiple faces are detected in selfie image
// Common errors
case "access_denied_exception":
case "invalid_parameter_exception":
case "rate_limit_exception":
case "internal_server_error":
}
}
}, cancellation: {
// sdk is canceled
})
QR scanner is a part of ID capturing. If client settings is enable QR scanner, it would be done on server side. The response is parsed automatically and send back to client object TVCardInfoResult
.
Method | Type | description |
---|---|---|
isLive | Bool | Determines whether the selfie is live or not |
score | Float | The score from 0 to 1 |
Method | Type | description |
---|---|---|
infos | [CardInfo] | List of information are extracted from the ID card |
CardInfo
Method | Type | description |
---|---|---|
field | String | Name of field example name, address... |
value | String | The value of each field |
Method | Type | description |
---|---|---|
isGood | Bool | Determines whether the selfie or id quality is good or not |
score | Float | The score from 0 to 1 |
error | String | If the quality is not good, the error will be Image too blur , Not white background , Image too bright , Image too dark |
Method | Type | description |
---|---|---|
matchResult | MatchResult | An enum matched , unmatched , unsure |
score | float | The score from 0 to 1 |
Method | Type | description |
---|---|---|
livenessResult | TVLivenessResult | Result of liveness verification if present |
faceCompareResult | TVCompareFacesResult | Result of face matching if present |
cardInfoResult | TVCardInfoResult | Result of ID extracting if present |
selfieSanityResult | TVSanityResult | Result of selfie sanity verification if present |
idSanityResult | TVSanityResult | Result of id sanity verification if present |
idFrontImageId | String | Image ID of the front id image got from server after uploaded |
idBackImageId | String | Image ID of the back id image got from server after uploaded |
selfieImageId | String | Image ID of the selfie image got from server after uploaded |
Method | Type | description |
---|---|---|
isGood | Bool | Determines whether the id card is tamperred or not |
score | Float | The score from 0 to 1 |
error | String | If the quality is not good, the detailed result will be returned |
Method | Type | description |
---|---|---|
cardType | TVCardType | List of supported cards can be found by let cardTypes: [TSCardType] = try TrustVisionSdk.getCardTypes() |
actionMode | ActionMode | Action mode |
cardInfoResult | TVCardInfoResult | Card information result |
frontIdImageId | String | Return image id of the uploaded front image. Should store somewhere to use other service like face compare |
backIdImageId | String | Return image id of the uploaded back image. Should store somewhere to use other service like face compare |
frontIdImage | UIImage | Image of id card's front side |
backIdImage | UIImage | Image of id card's back side |
selfieImage | UIImage | Image of selfie |
livenessResult | TVLivenessResult | Liveness result |
selfieSanityResult | TVSanityResult | Selfie sanity result |
selfieImageId | String | Return image id of the uploaded selfie image. Should store somewhere to use other service like face compare |
compareImageResult | TVCompareFacesResult | Faces comparing result |
idCardTamperingResult | TVDetectIdCardTamperingResult | Id card tampering check result |
idSanityResult | TVSanityResult | Id card sanity result |
Will be called in case failed. Parameters:
TVError
.Will be called in case the sdk is cancelled. No parameters