Protecting Identities
menu-openmenu-close

MRZ Scanner Library for Android

Scan a Machine Readable Zone (MRZ) from a (camera) image.

This is a fully functional sample app. Just load it with Android Studio, compile and install it on a device and follow the on-screen instructions.

Setup

First you need to create a MrzScanner object:

private final MrzScanner mrzScanner = new MrzScanner();

Then, you need to initialize it with you Activity:

Activity activity = getActivity();
if (!mrzScanner.init(activity)) {
	throw new RuntimeException("Failed to initialize MrzScanner");
}

After this, you need to set a region of interest within the view coordinates of the camera preview view. This function will map the points of interest in the given camera image to the preview screen:

mrzScanner.setRegionOfInterest(
		frameWidth, // native width of camera frame
		frameHeight, // native height of camera frame
		frameOrientation, // orientation in degrees of camera frame
		previewRect, // rectangle of camera preview in view coordinates
		roiRect); // region of interest in view coordinates

Reading the Chip

Finally, to scan a camera image in YUV format do:

final String mrz = mrzScanner.find(
		frameData,
		frameWidth,
		frameHeight,
		frameOrientation,
		canvas); // null or a canvas over the camera preview to draw into

Open Source Licenses