Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Last active March 12, 2020 06:49
Show Gist options
  • Save Lavanyagaur22/7b5b0bb63fec7f8b2baab2bf5d83a088 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/7b5b0bb63fec7f8b2baab2bf5d83a088 to your computer and use it in GitHub Desktop.
//detector is an instane of FirebaseVisionTextRecognizer
detector.processImage(image)
.addOnSuccessListener { firebaseVisionText ->
// Task completed successfully
for (block in firebaseVisionText.textBlocks) {
val blockText = block.text
val blockFrame = block.boundingBox
for (line in block.lines) {
val lineText = line.text
//once you get the text elements, you can easily extract the text, email address, name mentioned
//on the visiting card or any other image containing text.
//Apply your logic accordingly.
//One sample is shown below for extracting the number of the form:- 011-22246388
for (element in line.elements) {
var elementText = element.text
if(elementText.contains('-')){
val split= elementText.split('-')
var part1=""
var part2=""
split.let {
part1 = it[0]
part2 = it[1]
}
elementText=part1+part2
}
if(!elementText.isEmpty()){
var numeric = true
var num: Double = parseDouble("0")
try {
num = parseDouble(elementText)
} catch (e: NumberFormatException) {
numeric = false
}
if (numeric)
print("Phone number detected is $num")
else
print(" Phone number is not detected on the card.")
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment