从Firebase视觉文字检测总金额 [英] Total Amount detection from Firebase vision text

查看:102
本文介绍了从Firebase视觉文字检测总金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Google Firebase Vision工具包中检测总数.

I want to detect the total amount from Google Firebase Vision kit.

我做了什么?

我拥有视觉识别器的所有文本,但无法找到一种完美的算法来获取任何语言的总金额.

I have all the text from the vision recognizer but unable to find a perfect algorithm to get the total amount in any language.

我想要什么?

我有位图/文件,我想从该文件中获取总金额.该文本已被检测到.

I have Bitmap/file and I want to get the total amount from that file. The text is already detected.

我只希望它脱机.

推荐答案

ML Kit非常擅长检测图像中的文本并从中提取文本.但是它没有任何内置的总量"检测.

ML Kit is quite good at detecting text in an image, and extracting it from there. But it doesn't have any built-in "total amount" detection.

我们需要相同的功能,对于我们在Google I/O上进行的谈话,这笔费用跟踪器,结果发现它非常棘手.我们最终使用了这个非常简单的功能,该功能可以在检测到的文本中找到最大数量:

We needed this same functionality, for a talk we did at Google I/O building an expense tracker, and it turned out to be surprisingly tricky. We ended up using this very simple function, which finds the maximum number in the detected text:

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);
}

请注意,即使在有限的测试中,这也不总是很奏效.因此,您的里程可能会有所不同.

Note though that, even in our limited testing, this didn't always work great. So your mileage may vary.

该项目的完整代码在Github上: https://github.com/puf/zero-to-app-expenses .

Full code for the project is on Github: https://github.com/puf/zero-to-app-expenses.

这篇关于从Firebase视觉文字检测总金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆