如何使用TextRecognizer检测单词?它只能检测到TextBlocks [英] How to Detect Words with TextRecognizer? It can only detect TextBlocks
本文介绍了如何使用TextRecognizer检测单词?它只能检测到TextBlocks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够在下面的图像中检测到诸如青色色块之类的TextBlock,但我想使用TextRecogniger来检测Word
I am able to detect TextBlock like Cyan color block in below image but I want to detect Word with TextRecogniger
推荐答案
If you have a look at the reference (https://developers.google.com/android/reference/com/google/android/gms/vision/text/TextBlock), you will see that in the recognized block you will have a list of lines which has a list of elements.
然后,您应该在Processor类中得到如下所示的单词:
Then you should get the word in your Processor class with something like this:
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
SparseArray<TextBlock> items = detections.getDetectedItems();
for (int i = 0; i < items.size(); ++i) {
TextBlock item = items.valueAt(i);
List<Line> lines = (List<Line>) item.getComponents();
for (Line line : lines) {
List<Element> elements = (List<Element>) line.getComponents();
for (Element element : elements) {
String word = element.getValue();
}
}
}
}
这篇关于如何使用TextRecognizer检测单词?它只能检测到TextBlocks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文