Total Amount detection from Firebase vision text

前端 未结 1 1401
一个人的身影
一个人的身影 2021-01-27 05:44

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

What I did ?

I have all the text from the vision recognizer but unable to find a perfect algor

相关标签:
1条回答
  • 2021-01-27 06:24

    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.

    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.

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

    0 讨论(0)
提交回复
热议问题