我正在尝试从实时相机Feed中检测具有特定格式的文本,并在自动检测到该文本时显示Toast消息。 我能够检测到文本并在其周围放置一个方框。但是我很难显示祝酒词。
这是Processor
中的receiveDetections方法@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
mGraphicOverlay.clear();
SparseArray<TextBlock> items = detections.getDetectedItems();
for (int i = 0; i < items.size(); ++i) {
TextBlock item = items.valueAt(i);
if (item != null && item.getValue() != null) {
Log.d("OcrDetectorProcessor", "Text detected! " + item.getValue());
// Check if it is the correct format
if (item.getValue().matches("^\\d{3} \\d{3} \\d{4} \\d{4}")){
OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
mGraphicOverlay.add(graphic);
// Show the toast message
}
}
}
}
- &GT;显示祝酒词不是我的最终目标,如果我能够解决这个问题,我将解决主要问题。 - &GT;我正在建立在文本视觉api的代码实验室教程之上
答案 0 :(得分:7)
首先将来自OcrDetectorProcessor
的{{1}}类和来自该上下文的OcrCaptureActivity
传递给上下文。这段代码一次显示所有文本。如果您想逐个显示单词,则需要从runUiThread
项目中拆分。
TextBlock