Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
gradle/wrapper
src/main
.gitattributes
.gitignore
.gitmodules
MRTD-Reader-Sample.iml
Passport-Reader-Android-Sample.iml
README.md
build.gradle
gradlew
gradlew.bat

README.md

Maven metadata URL

Passport Reader SDK

Introduction

The Machine-Readable Travel Document (MRTD) Reader SDK lets your Android application read structured information in biometric travel documents (passports). In addition to the document and document holder information most biometric travel documents contain an image of the holder.

After obtaining the document information you can use Ver-ID Person SDK to detect the face on the image of the document holder and compare it to a live face of the person handling the device.

Installation

  1. In your app module's gradle.build file add the Ver-ID Maven repository:

    repositories {
    	maven {
    	    url 'https://dev.ver-id.com/artifactory/gradle-release'
    	    name 'Ver-ID'
    	}
    }
  2. Add the MRTD Reader dependency:

    dependencies {
    	implementation 'com.appliedrec:mrtd-reader:1.0.0'
    }
  3. If you plan using Ver-ID for face detection:

    1. Request an API secret for your app.

    2. Add Ver-ID in your app module's build.gradle dependencies:

      dependencies {
      	implementation 'com.appliedrec.verid:ui:1.7.1'
      }
    3. Add the following two lines in your app module's build.gradle:

      android {
      	defaultConfig {
      		renderscriptTargetApi 19
      		renderscriptSupportModeEnabled true
      	}
      }
    4. Open your app's AndroidManifest.xml file and add the following tag in replacing [your API secret] with the API secret:

      <meta-data 
         android:name="com.appliedrec.verid.apiSecret" 
         android:value="[your API secret]" />
    5. Clone Ver-ID model files into a VerIDModels directory in your project's assets folder:

      git lfs clone -b matrix-16 https://github.com/AppliedRecognition/Ver-ID-Models.git app/src/main/assets/VerIDModels

Reading Travel Documents

To read a travel document you will need to specify basic access control (BAC) variables. These are document number, date of birth and date of expiry.

If you know these simply create a new BACSpec object:

String docNumber = "document number"; // Enter the real number
Date dateOfBirth = new Date(); // Enter the real date
Date dateOfExpiry = new Date(); // Enter the deal date
BACSpec bacSpec = new BACSpec(docNumber, dateOfBirth, dateOfExpiry); 

The MRTD SDK contains a fragment class with a form that allows the user to enter the BAC variables. You can include this fragment in your activity and listen on its listener's onBACChanged:

public class MyActivity extends AppCompatActivity implements BACInputFragment.OnBACInputListener {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Do other things to set up your activity
		// ...
		if (savedInstanceState == null) {
			// Create BAC input fragment
			BACInputFragment bacInputFragment = BACInputFragment.newInstance(bacSpec);
			// Add the fragment to the fragment manager
			getSupportFragmentManager()
				.beginTransaction()
				.add(R.id.my_fragment_container, bacInputFragment)
				.commit();
		}
	}

    @Override
    public void onBACChanged(BACSpec bacSpec) {
        if (bacSpec != null) {
        	// User entered all BAC variables
        	// Enable a 'start scan' button or similar
        }
    }
}

To scan the travel document start the SDK's MRTDScanActivity and listen for its result:

private void startScan() {
	BACSpec bacSpec; // Obtained in the onBACChanged method of BACInputFragment.OnBACInputListener
	Intent intent = new Intent(this, MRTDScanActivity.class);
	intent.putExtra(MRTDScanActivity.EXTRA_BAC_SPEC, bacSpec);
	startActivityForResult(intent, 0);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK && data != null && data.hasExtra(MRTDScanActivity.EXTRA_MRTD_SCAN_RESULT)) {
    	// Scan succeeded
        MRTDScanResult scanResult = data.getParcelableExtra(MRTDScanActivity.EXTRA_MRTD_SCAN_RESULT);            
    } else if (resultCode == RESULT_OK && data != null && data.hasExtra(MRTDScanActivity.EXTRA_MRTD_SCAN_ERROR)) {
        // Failed to scan the document
        String errorMessage = data.getStringExtra(MRTDScanActivity.EXTRA_MRTD_SCAN_ERROR);
    }
}

Using Ver-ID Person SDK for Face Detection

The image of the travel document holder's face included in the MRTDScanResult can be used as input for Ver-ID face detection.

// Get the image from the travel document scan result
final Bitmap faceBitmap = BitmapFactory.decodeFile(scanResult.getImageFilePath());
// Load Ver-ID
VerIDFactory veridFactory = new VerIDFactory(this, new VerIDFactoryDelegate() {
	@Override
	public void veridFactoryDidCreateEnvironment(VerIDFactory verIDFactory, final VerID verID) {
	    // Ver-ID is now loaded
	    AsyncTask.execute(new Runnable() {
		@Override
		public void run() {
		    try {
			VerIDImage verIDImage = new VerIDImage(faceBitmap);
			Face[] faces = verID.getFaceDetection().detectFacesInImage(verIDImage, 1, 0);
			if (faces.length > 0) {
			    passportFaces = verID.getFaceRecognition().createRecognizableFacesFromFaces(faces, verIDImage);
			    // You now have a face that you can use for face recognition
			} else {
			    throw new Exception("Face not found");
			}
		    } catch (Exception e) {
			e.printStackTrace();
			// Handle the error
		    }
		}
	    });
	}

	@Override
	public void veridFactoryDidFailWithException(VerIDFactory verIDFactory, Exception e) {
	    // Ver-ID failed to load
	}
});

Comparing Travel Document Face to Live Face

Run Ver-ID liveness detection session in your activity:

private void captureLiveFace() {
	if (verID == null) {
		return;
	}
	LivenessDetectionSessionSettings sessionSettings = new LivenessDetectionSessionSettings();
        Intent intent = new VerIDSessionIntent<>(this, verID, sessionSettings);
        startActivityForResult(intent, REQUEST_CODE_LIVENESS_DETECTION);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_LIVENESS_DETECTION && resultCode == RESULT_OK && data != null && data.hasExtra(VerIDSessionActivity.EXTRA_RESULT)) {
    	VerIDSessionResult sessionResult = data.getParcelableExtra(VerIDSessionActivity.EXTRA_RESULT);
        if (sessionResult != null && sessionResult.getError() == null) {
		RecognizableFace[] recognizableFaces = sessionResult.getFacesSuitableForRecognition(Bearing.STRAIGHT);
		// You can now compare the collected faces to the face from the passport
		try {
			float score = verID.getFaceRecognition().compareSubjectFacesToFaces(passportFaces, recognizableFaces);
			float threshold = verID.getFaceRecognition().getAuthenticationThreshold();
			// If the score >= threshold the user is the same user as the passport holder
		} catch (Exception e) {
		}
	}
    }
}

API Reference

You can’t perform that action at this time.