如何用TextRecognizer检测单词?它只能检测的TextBlocks

问题描述:

我能够检测的TextBlock像下面的图片青色块,但我想检测的Word与TextRecogniger如何用TextRecognizer检测单词?它只能检测的TextBlocks

如果你看一下参考(https://developers.google.com/android/reference/com/google/android/gms/vision/text/TextBlock),你将在已识别的块中看到您将拥有包含元素列表的行列表。

那么你应该得到这个词在你的处理器类是这样的:

@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(); 
      } 
     } 
    } 
} 
+0

不getComponent()方法的工作如上面给出的参考 –