Document Quality Analyzer | Android Document Scanner
The Document Quality Analyzer component allows you to detect the quality of text in still images or frames from the camera.
The Document Quality Analyzer is available only as a classic component (types of components are explained here).
Integration
Take a look at our Example App to see how to integrate the Document Quality Analyzer.
- Classic UI Components: document-quality-analyzer
Add Feature as a Dependency
DocumentQualityAnalyzer
is available with SDK Package 1. You have to add the following dependencies for it:
implementation("io.scanbot:sdk-package-1:$scanbotSdkVersion")
implementation("io.scanbot:sdk-docqualityanalyzer-assets:$latestSdkVersion")
Initialize the SDK
The Scanbot SDK must be initialized before use. Add the following code snippet to your Application
class:
import io.scanbot.sdk.ScanbotSDKInitializer
class ExampleApplication : Application() {
override fun onCreate() {
super.onCreate()
// Initialize the Scanbot Scanner SDK:
ScanbotSDKInitializer().initialize(this)
}
}
Classic component
Try our Document Quality Analyzer Demo App or check the following step by step integration instructions.
Add feature depedencies and initialize the SDK
First of all, you have to add the SDK package and feature dependencies as described here.
Initialize the SDK as described here. More information about the SDK license initialization can be found here.
Analyze live preview image
First of all, ScanbotCameraXView
needs to be set up. For this refer to the Using ScanbotCameraView chapter.
Next, set up the analyzer, create FrameHandler
and attach it to ScanbotCameraXView
:
val documentQualityAnalyzer = ScanbotSDK(context).createDocumentQualityAnalyzer()
resultCaption = findViewById<TextView>(R.id.doc_quality_analyzer_result)
...
val qualityAnalyzerFrameHandler = object : FrameHandler {
@Synchronized
override fun handleFrame(previewFrame: FrameHandler.Frame): Boolean {
val qualityResult: DocumentQualityResult? = documentQualityAnalyzer.analyze(
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 {
resultCaption.text = "Image quality: ${qualityResult?.name ?: "UNKNOWN"}"
}
return false
}
}
...
cameraView.addFrameHandler(qualityAnalyzerFrameHandler)
Now the live frames will be processed inside FrameHandler
, passed to documentQualityAnalyzer
and the resulting image quality value will be displayed in a TextView
.
Analyzed results are represented by io.scanbot.sdk.process.model.DocumentQualityResult
enum, with the following values:
DocumentQualityResult.NO_DOCUMENT
- No document was foundDocumentQualityResult.VERY_POOR
- The quality of the document is very poorDocumentQualityResult.POOR
- The quality of the document is poorDocumentQualityResult.REASONABLE
- The quality of the document is reasonableDocumentQualityResult.GOOD
- The quality of the document is goodDocumentQualityResult.EXCELLENT
- The quality of the document is excellent
Analyze a still image
Alternative to live detection, you can run the analyzer 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)
val documentQuality: DocumentQualityResult? = documentQualityAnalyzer.analyzeInBitmap(bitmap, imageOrientation)
}
Want to scan longer than one minute?
Generate your free "no-strings-attached" Trial License and properly test the Scanbot SDK.
Get your free Trial LicenseWhat do you think of this documentation?
What can we do to improve it? Please be as detailed as you like.