Created
February 21, 2021 11:45
-
-
Save saugatrai33/6a7c6c31ead63c83da6f21d8b047e647 to your computer and use it in GitHub Desktop.
Using MLKit to recognise text in Android.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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