Skip to content

Commit 73ce60d

Browse files
committed
fix imageRef usage logic
1 parent a2de557 commit 73ce60d

File tree

1 file changed

+12
-3
lines changed
  • classic-components-example/camera-view-aspect-ratio-finder/src/main/java/io/scanbot/example

1 file changed

+12
-3
lines changed

classic-components-example/camera-view-aspect-ratio-finder/src/main/java/io/scanbot/example/MainActivity.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ import io.scanbot.sdk.documentscanner.DocumentScanner
2626
import io.scanbot.sdk.documentscanner.DocumentScannerParameters
2727
import io.scanbot.sdk.geometry.AspectRatio
2828
import io.scanbot.sdk.image.ImageRef
29+
import io.scanbot.sdk.imageprocessing.ScanbotSdkImageProcessor
2930
import io.scanbot.sdk.process.ImageProcessor
3031
import io.scanbot.sdk.ui.camera.AdaptiveFinderOverlayView
3132
import io.scanbot.sdk.ui.camera.ScanbotCameraXView
3233
import io.scanbot.sdk.ui.camera.ShutterButton
34+
import io.scanbot.sdk.util.PolygonHelper
3335

3436
class 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

Comments
 (0)