From 76f94c1b48c99138a99392e1fea0fcd72d34ec1d Mon Sep 17 00:00:00 2001 From: Reuben Mangubat Date: Thu, 7 Jan 2021 09:35:26 +0800 Subject: [PATCH] Fix bounding box for ID PASS Lite --- .../idpass/smartscanner/lib/SmartScannerActivity.kt | 2 +- .../org/idpass/smartscanner/lib/extension/Image.kt | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core-lib/src/main/java/org/idpass/smartscanner/lib/SmartScannerActivity.kt b/core-lib/src/main/java/org/idpass/smartscanner/lib/SmartScannerActivity.kt index 6e8e7dda..e03f213f 100644 --- a/core-lib/src/main/java/org/idpass/smartscanner/lib/SmartScannerActivity.kt +++ b/core-lib/src/main/java/org/idpass/smartscanner/lib/SmartScannerActivity.kt @@ -382,7 +382,7 @@ class SmartScannerActivity : AppCompatActivity(), OnClickListener { val mediaImage = imageProxy.image if (mediaImage != null) { val rot = imageProxy.imageInfo.rotationDegrees - val bf = mediaImage.toBitmap(rot) + val bf = mediaImage.toBitmap(rot, mode) val cropped = if (rot == 90 || rot == 270) Bitmap.createBitmap( bf, bf.width / 2, diff --git a/core-lib/src/main/java/org/idpass/smartscanner/lib/extension/Image.kt b/core-lib/src/main/java/org/idpass/smartscanner/lib/extension/Image.kt index dfdb5166..30b4234c 100644 --- a/core-lib/src/main/java/org/idpass/smartscanner/lib/extension/Image.kt +++ b/core-lib/src/main/java/org/idpass/smartscanner/lib/extension/Image.kt @@ -22,12 +22,13 @@ import android.media.Image import android.util.Base64 import android.util.Log import org.idpass.smartscanner.lib.SmartScannerActivity +import org.idpass.smartscanner.lib.config.Modes import java.io.ByteArrayOutputStream import java.io.File import java.io.FileOutputStream -fun Image.toBitmap(rotation: Int = 0): Bitmap { +fun Image.toBitmap(rotation: Int = 0, mode: String?): Bitmap { val yBuffer = planes[0].buffer // Y val uBuffer = planes[1].buffer // U val vBuffer = planes[2].buffer // V @@ -47,14 +48,17 @@ fun Image.toBitmap(rotation: Int = 0): Bitmap { val out = ByteArrayOutputStream() val rect = Rect() + // Use higher value of 6 for barcode which fixes bounding box issues upon scanning, + // and mrz uses previous default value of 4 + val scaleIdentifier = if (mode == Modes.BARCODE.value) 6 else 4 if (rotation == 90 || rotation == 270) { - rect.left = this.width / 4 + rect.left = this.width / scaleIdentifier rect.top = 0 rect.right = this.width - rect.left rect.bottom = this.height } else { rect.left = 0 - rect.top = this.height / 4 + rect.top = this.height / scaleIdentifier rect.right = this.width rect.bottom = this.height - rect.top }