Skip to main content

Scanning a medical certificate from an image file with the Android Medical Certificate Scanner Module

In addition to detecting MC/"AU-Bescheinigung" forms on a live camera stream, the SDK can extract content from still images imported from the gallery or any other source.

To see the complete integration and the Medical Certificate Scanner in action, take a look at the example apps:

Adding the feature as a dependency

The Medical Certificate Scanner is included in Scanbot SDK package 4. Therefore, add the dependency io.scanbot:sdk-package-4 or higher in your build.gradle:

implementation("io.scanbot:sdk-package-4:$latestSdkVersion")
implementation("io.scanbot:sdk-mc-assets:$latestSdkVersion")

For medical certificates that contain additional information in the barcode, also add the following dependency:

implementation("io.scanbot:sdk-barcode-assets:$latestSdkVersion")
caution

Do not use multiple scanners (e.g., MRZ Scanner and Credit Card Scanner) at the same time.

Each scanner instance requires a lot of memory, GPU, and processor resources. Using multiple scanners will lead to performance issues for the entire application.

Initializing the SDK

Before use, the Scanbot SDK needs to be initialized. The following code snippet should be added to your Application class:

Initialize SDK
loading...

Processing the image

To select an image from the photo library and run detection on it, a class for an image import contract is created using the modern Android result API.

class ImportImageContract(private val context: Context) : ActivityResultContract<Unit, Bitmap?>() {
override fun createIntent(context: Context, input: Unit): Intent {
// An image is selected from the photo library and document detection is run on it:
val imageIntent = Intent()
imageIntent.type = "image/*"
imageIntent.action = Intent.ACTION_GET_CONTENT
imageIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, false)
imageIntent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false)

return Intent.createChooser(imageIntent, "Select a picture")
}

private fun processGalleryResult(data: Intent): Bitmap? {
val imageUri = data.data
return MediaStore.Images.Media.getBitmap(context.contentResolver, imageUri)
}

override fun parseResult(resultCode: Int, intent: Intent?): Bitmap? {
return if (resultCode == Activity.RESULT_OK && intent != null) {
return processGalleryResult(intent)
} else {
null
}
}
}

To run the gallery call and get a Bitmap using ImportImageContract, the following code is used:

 val galleryImageLauncher =
registerForActivityResult(ImportImageContract(this)) { resultEntity ->
lifecycleScope.launch(Dispatchers.Default) {
val activity = this@MainActivity
val sdk = ScanbotSDK(activity)
if (!sdk.licenseInfo.isValid) {
withContext(Dispatchers.Main) {
Toast.makeText(
activity,
"License has expired!",
Toast.LENGTH_LONG
).show()
}
} else {
resultEntity?.let { bitmap ->
// Image processing is carried out
// processImage()
}
}
}
}
findViewById<View>(R.id.import_image).setOnClickListener {
galleryImageLauncher.launch(Unit)
}

Creating a scanner

Create Medical Certificate Scanner
loading...
caution

Each call to createMedicalCertificateScanner() will create a new MedicalCertificateScanner and initialize memory for it. If more than one import operation is expected, do not create new scanners for each operation.

Detection

The Scanbot SDK is used to detect the desired element on the imported bitmap.

Extracting medical certificate data from an image
loading...

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License