我想检测 Google Firebase Vision 套件的总量。
我做了什么?
我拥有来自视觉识别器的所有文本,但无法找到完美的算法来获取任何语言的总量。
我想要什么?
我有位图/文件,我想从该文件中获取总金额。文本已被检测到。
我只希望它可以离线使用。
最佳答案
ML Kit 非常擅长检测图像中的文本并从中提取文本。但它没有任何内置的“总量”检测。
我们需要同样的功能,用于 talk we did at Google I/O building an expense tracker ,结果却出人意料地棘手。我们最终使用了这个非常简单的函数,它可以找到检测到的文本中的最大数字:
exports.findTotal = function findTotal(detections) {
const regex = '^[$]?\s*(\\d+[\\.,]\\d{2})$';
const amounts = detections
.filter(text => text.description.match(regex))
.map(text => text.description.match(regex)[1])
.map(text => text.replace(',', '.'))
.map(text => Number(text))
.concat([0.0]);
return Math.max.apply(null, amounts);
}
请注意,即使在我们有限的测试中,这也并不总是有效。因此您的里程可能会有所不同。
该项目的完整代码位于 Github 上:https://github.com/puf/zero-to-app-expenses .
关于android - 从 Firebase 视觉文本检测总量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58073958/