Basic processing steps:
private fun runTextRecognition(bitmap: Bitmap) {
val image = FirebaseVisionImage.fromBitmap(bitmap)
val recognizer = FirebaseVision.getInstance().onDeviceTextRecognizer
recognizer.processImage(image).addOnSuccessListener {
processTextRecognitionResult(it)
isOcrImageFlowLocked = false
}.addOnFailureListener { e: Exception ->
e.printStackTrace()
handleError(e)
isOcrImageFlowLocked = false
}
}
private fun processTextRecognitionResult(texts: FirebaseVisionText) {
var txt = ""
var maxFloat = 0f
for (block in texts.textBlocks) {
for (line in block.lines) {
line.text.toFloatOrNull()?.let {
maxFloat = maxOf(maxFloat, it)
}
for (element in line.elements) {
txt += element.text + " "
}
}
}
Timber.d("Temperature Detected: $maxFloat")
Timber.d("Text Detected: $txt")
ocrImageObserver!!.value = if (floor(maxFloat) == ceil(maxFloat)) {
maxFloat.toInt().toString()
} else {
maxFloat.toString()
}
if (maxFloat == 0f) {
Toast.makeText(requireContext(), "No Numbers found", Toast.LENGTH_SHORT).show()
}
}
Also, Tweak image resolution accordingly and see which is best for our use case.