我想创建一个类似 CamCard 的应用程序,它将作为 ocr 工作并将文本填充到特定字段中,我已经使用 Firebase MLKit 从图像中识别文本,但问题是它现在给我文本作为列表如何获取哪些文本与哪个相关我的基本实现如下
FirebaseApp.initializeApp(this);
FirebaseVisionImage image = FirebaseVisionImage.fromBitmap(bm);
FirebaseVisionTextRecognizer textRecognizer = FirebaseVision.getInstance()
.getOnDeviceTextRecognizer();
textRecognizer.processImage(image)
.addOnSuccessListener(new OnSuccessListener<FirebaseVisionText>() {
@Override
public void onSuccess(FirebaseVisionText result) {
// Task completed successfully
// ...
String resultText = result.getText();
for (FirebaseVisionText.TextBlock block : result.getTextBlocks()) {
String blockText = block.getText();
Float blockConfidence = block.getConfidence();
List<RecognizedLanguage> blockLanguages = block.getRecognizedLanguages();
Point[] blockCornerPoints = block.getCornerPoints();
Rect blockFrame = block.getBoundingBox();
for (FirebaseVisionText.Line line : block.getLines()) {
String lineText = line.getText();
Float lineConfidence = line.getConfidence();
List<RecognizedLanguage> lineLanguages = line.getRecognizedLanguages();
Point[] lineCornerPoints = line.getCornerPoints();
Rect lineFrame = line.getBoundingBox();
for (FirebaseVisionText.Element element : line.getElements()) {
String elementText = element.getText();
Float elementConfidence = element.getConfidence();
List<RecognizedLanguage> elementLanguages = element.getRecognizedLanguages();
Point[] elementCornerPoints = element.getCornerPoints();
Rect elementFrame = element.getBoundingBox();
}
}
}
}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// Task failed with an exception
// ...
}
});
从上面的侦听器中,我将获得所有文本的列表,请演示如何将文本设置为相应的字段