Skip to content

Instantly share code, notes, and snippets.

@saugatrai33
Created February 21, 2021 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saugatrai33/6a7c6c31ead63c83da6f21d8b047e647 to your computer and use it in GitHub Desktop.
Save saugatrai33/6a7c6c31ead63c83da6f21d8b047e647 to your computer and use it in GitHub Desktop.
Using MLKit to recognise text in Android.
private fun recognizeImage() {
val jokeImg = BitmapFactory.decodeResource(resources, R.drawable.joke_shampoo)
val inputJokeImg = InputImage.fromBitmap(jokeImg, 0)
val textRecognizer = TextRecognition.getClient()
textRecognizer.process(inputJokeImg)
.addOnSuccessListener { texts ->
run {
Log.d("MainActivity", "recognizeImage: ${texts.text}")
recognizedTextShow.text = texts.text
}
}
.addOnFailureListener { e ->
Log.d(
"MainActivity",
"recognizeImage: text detection error:: $e"
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment