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
how to read a number from an image?
提问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
回答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);
}