android - 如何从 sparseArray 中减去单个字符串?
问题描述
我一直在使用 Android Mobile Vision OCR API 一段时间。一切都很完美,直到我发现我只需要从整个 SparseArray 中提取单个单词(Mobile Vision API 默认返回是在 SparseArray 中定义的 TextBlocks)
SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame);
for (int i = 0; i < textBlocks.size(); i++) {
TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i));
List<Line> lines = (List<Line>) textBlock.getComponents();
for (Line line : lines) {
List<Element> elements = (List<Element>)
line.getComponents();
for (Element element : elements) {
word = element.getValue();
Log.d(TAG, "word Read : " + word);
}
}
}
当我检查
Log.d(TAG, "word Read : " + word);
它重复打印出 SparseArray 中的所有元素
看来我在问一个不太明显的问题。但是我可以从上面打印的那些“单词”中提取一个或几个单词吗?例如,我想提取字符大于 12 且包含数字的单词。
任何帮助或提示将不胜感激。
解决方案
您可以添加逻辑表达式来过滤结果,如下所示:
word = element.getValue();
if (word .length() > 12 && word .matches("[0-9]+")) {
Log.d(TAG, "word Read : " + word);
}
推荐阅读
- javascript - 试图从图像中获取颜色
- matlab - Matlab:发布函数运行无限循环
- javascript - 将变量传递给javascript中的函数参数
- r - 为什么置信带不覆盖 geom_point 图中的最后一点
- javascript - d3.keys() 语法说明?
- ember.js - ember 将 mirage 请求重定向到导入模块中的另一个路由
- php - 在测试用例之间共享 PHPUnit 测试
- javascript - Javascript:blob 链接不起作用
- winforms - 使表单转到随机位置并保持在屏幕尺寸内 - Windows 表单
- c# - 从 SQL Server 读取日期