java 如何从图像中读取数字?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7420166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:53:52  来源:igfitidea点击:

how to read a number from an image?

java

提问by Dail

I have some images that inside have a string with a number, like: "We have 3 books" I need to get 3: Is there a library in Java that can read the image and extract the number? or maybe the string then I will parse that string to find the number?

我有一些图像,里面有一个带数字的字符串,例如:“我们有 3 本书”我需要得到 3:Java 中是否有可以读取图像并提取数字的库?或者也许是字符串然后我会解析该字符串以找到数字?

Thank you

谢谢

回答by SpeedBirdNine

It is called Optical Character Recognition (OCR). See thisA few classes and libraries that may help you are:

它被称为光学字符识别 (OCR)。请参阅此一些可能对您有帮助的类和库是:

asprise

惊喜

abstractnonsense

抽象的废话

jocr

约克

tess4j

泰斯4j

回答by Hilmar

with tess4jyou could try this:

使用tess4j你可以试试这个:

public static void main(final String[] args) throws Exception {
    final File imageFile = new File("imageWith Digits.jpg");
    final ITesseract instance = new Tesseract();
    instance.setTessVariable("tessedit_char_whitelist", "0123456789");
    final String result = instance.doOCR(imageFile);
    System.out.println(result);
}