@@ -26,10 +26,12 @@ import io.scanbot.sdk.documentscanner.DocumentScanner
2626import io.scanbot.sdk.documentscanner.DocumentScannerParameters
2727import io.scanbot.sdk.geometry.AspectRatio
2828import io.scanbot.sdk.image.ImageRef
29+ import io.scanbot.sdk.imageprocessing.ScanbotSdkImageProcessor
2930import io.scanbot.sdk.process.ImageProcessor
3031import io.scanbot.sdk.ui.camera.AdaptiveFinderOverlayView
3132import io.scanbot.sdk.ui.camera.ScanbotCameraXView
3233import io.scanbot.sdk.ui.camera.ShutterButton
34+ import io.scanbot.sdk.util.PolygonHelper
3335
3436class MainActivity : AppCompatActivity (), DocumentScannerFrameHandler.ResultHandler {
3537 private lateinit var cameraView: ScanbotCameraXView
@@ -186,11 +188,18 @@ class MainActivity : AppCompatActivity(), DocumentScannerFrameHandler.ResultHand
186188 this .ignoreOrientationMismatch = true
187189 }
188190 })
189- val polygon = scanner.run (image).getOrNull()?.pointsNormalized ? : throw Exception (" Document detection failed" )
191+ val polygon = scanner.run (image).getOrNull()?.pointsNormalized
192+ ? : throw Exception (" Document detection failed" )
193+
194+ val polygonCrop =
195+ polygon.takeIf { it.isNotEmpty() && it.size == 4 } ? : PolygonHelper .getFullPolygon()
196+ var documentImage = ScanbotSdkImageProcessor .create()
197+ .crop(image, polygonCrop)
198+ .getOrThrow()
199+ documentImage = ScanbotSdkImageProcessor .create().resize(documentImage, 200 ).getOrThrow()
190200
191- val documentImage = ImageProcessor (image).crop(polygon).processedBitmap().getOrNull()
192201 resultView.post {
193- resultView.setImageBitmap(documentImage)
202+ resultView.setImageBitmap(documentImage.toBitmap().getOrNull() )
194203 cameraView.continuousFocus()
195204 cameraView.startPreview()
196205 }
0 commit comments