Skip to main content

Using Blur Estimator | Android Document Scanner

The Blur Estimator component allows you to detect the blurriness of still or live images. The result of estimation is a Float number within [0..1] range, where 0.0 is the most crisp image and 1.0 is the most blurred image.

You can check the GitHub example or just follow the steps below.

SDK setup#

To start using Blur Estimator, first add the dependency for Scanbot SDK:


Then, at SDK initialization phase you need to set the ScanbotSDKInitializer flag for pre-fetching blobs for blur detector:

ScanbotSDKInitializer()    ...    .prepareBlurEstimatorBlobs(true)    .initialize(this)

SDK initialization is described in detail in the SDK Initialization section.

Estimating live preview image example#

First of all, ScanbotCameraView needs to be set up. For this refer to Using ScanbotCameraView chapter.

Next, set up estimator, create FrameHandler and attach it to ScanbotCameraView:

val blurEstimator = ScanbotSDK(this).createBlurEstimator()resultCaption = findViewById<TextView>(
val blurFrameHandler = object : FrameHandler {
    @Synchronized    override fun handleFrame(previewFrame: FrameHandler.Frame): Boolean {        val blurValue = blurEstimator.estimate(            previewFrame.frame, previewFrame.width, previewFrame.height,            previewFrame.frameOrientation)
          // NOTE: 'handleFrame' method runs in background thread - don't forget to switch to main before touching any Views        runOnUiThread {            resultCaptionTextView.text = String.format("Image blurriness: %.2f", blurValue)        }                return false    }}    ...

Now the live frames will be processed inside FrameHandler, passed to blurEstimator and the resulting blurriness value will be displayed in a TextView.

Estimating blur of a still image#

Alternative to live detection, you can run estimator on an image that has just been captured or one that you have retrieved from the gallery:

override fun onPictureTaken(image: ByteArray, captureInfo: CaptureInfo) {    val bitmap = BitmapFactory.decodeByteArray(image, 0, image.size)    blurEstimator.estimateInBitmap(bitmap, imageOrientation)}