Skip to content

Commit 6263bc0

Browse files
committed
fixed mrz-scanner module
1 parent 4caf283 commit 6263bc0

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

classic-components-example/mrz-scanner/src/main/java/io/scanbot/example/ExampleApplication.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.scanbot.example
22

33
import android.app.Application
4-
import io.scanbot.sap.SdkFeature
54
import io.scanbot.sdk.ScanbotSDK
65
import io.scanbot.sdk.ScanbotSDKInitializer
76
import io.scanbot.sdk.util.log.LoggerProvider
@@ -24,11 +23,9 @@ class ExampleApplication : Application() {
2423
.withLogging(true)
2524
// TODO 2/2: Enable the Scanbot SDK license key
2625
//.license(this, licenseKey)
27-
.licenceErrorHandler { status, feature, statusMessage ->
26+
.licenseErrorHandler { status, feature, statusMessage ->
2827
LoggerProvider.logger.d("ExampleApplication", "+++> License status: ${status.name}. Status message: $statusMessage")
29-
if (feature != SdkFeature.NoSdkFeature) {
30-
LoggerProvider.logger.d("ExampleApplication", "+++> Feature not available: ${feature.name}")
31-
}
28+
LoggerProvider.logger.d("ExampleApplication", "+++> Feature not available: ${feature.name}")
3229
}
3330
//.sdkFilesDirectory(this, getExternalFilesDir(null)!!)
3431
.initialize(this)
@@ -38,6 +35,6 @@ class ExampleApplication : Application() {
3835
val licenseInfo = ScanbotSDK(this).licenseInfo
3936
LoggerProvider.logger.d("ExampleApplication", "License status: ${licenseInfo.status}")
4037
LoggerProvider.logger.d("ExampleApplication", "License isValid: ${licenseInfo.isValid}")
41-
LoggerProvider.logger.d("ExampleApplication", "License expirationDate: ${licenseInfo.expirationDate}")
38+
LoggerProvider.logger.d("ExampleApplication", "License expirationDate: ${licenseInfo.expirationDateString}")
4239
}
4340
}

classic-components-example/mrz-scanner/src/main/java/io/scanbot/example/MRZLiveScanningActivity.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import androidx.appcompat.app.AppCompatActivity
1111
import androidx.core.app.ActivityCompat
1212
import androidx.core.content.ContextCompat
1313
import androidx.core.view.WindowCompat
14+
import io.scanbot.common.getOrThrow
1415
import io.scanbot.example.common.applyEdgeToEdge
1516
import io.scanbot.sdk.ScanbotSDK
1617
import io.scanbot.sdk.camera.FrameHandlerResult
17-
import io.scanbot.sdk.common.AspectRatio
1818
import io.scanbot.sdk.documentdata.entity.MRZ
19+
import io.scanbot.sdk.geometry.AspectRatio
1920
import io.scanbot.sdk.mrz.MrzScannerFrameHandler
2021
import io.scanbot.sdk.ui.camera.FinderOverlayView
2122
import io.scanbot.sdk.ui.camera.ScanbotCameraXView
@@ -52,7 +53,7 @@ class MRZLiveScanningActivity : AppCompatActivity() {
5253
// Get the scanbot sdk instance
5354
val scanbotSDK = ScanbotSDK(this)
5455
// Configure mrz scanner
55-
val mrzScanner = scanbotSDK.createMrzScanner()
56+
val mrzScanner = scanbotSDK.createMrzScanner().getOrThrow()
5657
// Attach mrz scanner to the camera
5758
mrzScannerFrameHandler = MrzScannerFrameHandler.attach(cameraView, mrzScanner)
5859
// Handle live mrz scanning results

classic-components-example/mrz-scanner/src/main/java/io/scanbot/example/MRZStillImageDetectionActivity.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@ import androidx.activity.result.PickVisualMediaRequest
1111
import androidx.activity.result.contract.ActivityResultContracts
1212
import androidx.appcompat.app.AppCompatActivity
1313
import androidx.lifecycle.lifecycleScope
14+
import io.scanbot.common.getOrNull
15+
import io.scanbot.common.getOrThrow
1416
import io.scanbot.example.MRZResultActivity.Companion.newIntent
1517
import io.scanbot.example.common.Const
1618
import io.scanbot.example.common.applyEdgeToEdge
1719
import io.scanbot.example.common.showToast
1820
import io.scanbot.example.databinding.ActivityMrzStillImageScanningBinding
1921
import io.scanbot.sdk.ScanbotSDK
2022
import io.scanbot.sdk.docprocessing.Page
23+
import io.scanbot.sdk.image.ImageRef
2124
import io.scanbot.sdk.ui_v2.common.activity.registerForActivityResultOk
2225
import io.scanbot.sdk.ui_v2.document.DocumentScannerActivity
2326
import io.scanbot.sdk.ui_v2.document.configuration.DocumentScanningFlow
@@ -30,7 +33,7 @@ class MrzStillImageScanningActivity : AppCompatActivity() {
3033

3134
private val binding by lazy { ActivityMrzStillImageScanningBinding.inflate(layoutInflater) }
3235
private val scanbotSdk by lazy { ScanbotSDK(this) }
33-
private val mrzScanner by lazy { scanbotSdk.createMrzScanner().apply {
36+
private val mrzScanner by lazy { scanbotSdk.createMrzScanner().getOrThrow().apply {
3437
setConfiguration(this.copyCurrentConfiguration().apply {
3538
// frame accumulation is not needed for still image scanning
3639
this.frameAccumulationConfiguration.minimumNumberOfRequiredFramesWithEqualScanningResult = 1
@@ -103,7 +106,7 @@ class MrzStillImageScanningActivity : AppCompatActivity() {
103106
}
104107

105108
private suspend fun scanMrz(page: Page) {
106-
val result = mrzScanner.scanFromBitmap(page.documentImage, 0)
109+
val result = mrzScanner.run(page.documentImageRef!!).getOrNull()
107110

108111
withContext(Dispatchers.Main) {
109112
binding.progressBar.visibility = View.GONE
@@ -120,14 +123,15 @@ class MrzStillImageScanningActivity : AppCompatActivity() {
120123

121124
private suspend fun importImageToPage(uri: Uri) {
122125
val page = withContext(Dispatchers.Default) {
123-
val inputStream = contentResolver.openInputStream(uri)
124-
val bitmap = BitmapFactory.decodeStream(inputStream)
126+
val inputStream = contentResolver.openInputStream(uri) ?: throw IllegalStateException("Cannot open input stream from URI: $uri")
127+
val image = ImageRef.fromInputStream(inputStream)
125128

126129
val document = scanbotSdk.documentApi.createDocument()
127-
val page = document.addPage(bitmap)
130+
val page = document.addPage(image)
128131

132+
val documentScanner = scanbotSdk.createDocumentScanner().getOrThrow()
129133
val contourResult =
130-
scanbotSdk.createDocumentScanner().scanFromBitmap(bitmap)?.pointsNormalized ?: kotlin.run {
134+
documentScanner.run(image).getOrNull()?.pointsNormalized ?: kotlin.run {
131135
Log.e(Const.LOG_TAG, "Error finding document on page " + page.uuid)
132136
PolygonHelper.getFullPolygon()
133137
}

0 commit comments

Comments
 (0)