Skip to content

Instantly share code, notes, and snippets.

@bapspatil
Created April 19, 2019 07:22
Show Gist options
  • Save bapspatil/c72cf083a1a8d8aa1fafaea60fc2ebff to your computer and use it in GitHub Desktop.
Save bapspatil/c72cf083a1a8d8aa1fafaea60fc2ebff to your computer and use it in GitHub Desktop.
val result = recognizer.processImage(image)
.addOnSuccessListener { result ->
// Task completed successfully
// Text recognition results
val resultText = result.text
// `FirebaseVisionText` is made of `TextBlock`s...
for (block in result.textBlocks) {
// ...and each `TextBlock` has
// text, confidence level, list of recognized languages and corner points and frame in which the text was detected...
val blockText = block.text
val blockConfidence = block.confidence
val blockLanguages = block.recognizedLanguages
val blockCornerPoints = block.cornerPoints
val blockFrame = block.boundingBox
// ...and each `TextBlock` is made of `Line`s...
for (line in block.lines) {
// ...which again have text, confidence level, list of recognized languages, corner points and the frame in which the text was detected...
val lineText = line.text
val lineConfidence = line.confidence
val lineLanguages = line.recognizedLanguages
val lineCornerPoints = line.cornerPoints
val lineFrame = line.boundingBox
// ... and each `Line` is further made of `Element`s...
for (element in line.elements) {
// ...and each `Element` has
// text, confidence level, list of recognized languages, corner points and the frame in which the text was detected.
val elementText = element.text
val elementConfidence = element.confidence
val elementLanguages = element.recognizedLanguages
val elementCornerPoints = element.cornerPoints
val elementFrame = element.boundingBox
}
}
}
}
.addOnFailureListener {
// Task failed with an exception
longToast("Failed to recognize text!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment