Skip to content

Commit

Permalink
Fix bounding box for ID PASS Lite
Browse files Browse the repository at this point in the history
  • Loading branch information
rjmangubat23 committed Jan 8, 2021
1 parent cef66c4 commit 76f94c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 76f94c1

Please sign in to comment.