-
-
Save ingenious3/bc2529e585c701d4ddbef6274498575e to your computer and use it in GitHub Desktop.
on device text-recognition (MLKit-TextRecognition repository)
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 void runTextRecognition() { | |
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(((GlideBitmapDrawable)imageView.getDrawable()).getBitmap()); | |
FirebaseVisionTextRecognizer detector = FirebaseVision.getInstance() | |
.getOnDeviceTextRecognizer(); | |
detector.processImage(image) | |
.addOnSuccessListener( | |
new OnSuccessListener<FirebaseVisionText>() { | |
@Override | |
public void onSuccess(FirebaseVisionText texts) { | |
processTextRecognitionResult(texts); | |
} | |
}) | |
.addOnFailureListener( | |
new OnFailureListener() { | |
@Override | |
public void onFailure(@NonNull Exception e) { | |
e.printStackTrace(); | |
} | |
}); | |
} | |
private void processTextRecognitionResult(FirebaseVisionText texts) { | |
List<FirebaseVisionText.TextBlock> blocks = texts.getTextBlocks(); | |
if (blocks.size() == 0) { | |
showToast("No text found"); | |
return; | |
} | |
mGraphicOverlay.clear(); | |
imageView.setImageDrawable(getResources().getDrawable(R.drawable.no_image)); | |
for (int i = 0; i < blocks.size(); i++) { | |
List<FirebaseVisionText.Line> lines = blocks.get(i).getLines(); | |
for (int j = 0; j < lines.size(); j++) { | |
List<FirebaseVisionText.Element> elements = lines.get(j).getElements(); | |
for (int k = 0; k < elements.size(); k++) { | |
Graphic textGraphic = new TextGraphic(mGraphicOverlay, elements.get(k)); | |
mGraphicOverlay.add(textGraphic); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment