我正在扫描单个字母和数字。所有数字都应该被解析为numbers[]。但它总是捕获异常。例如:结果是“3”,但由于某种原因我无法解析它。我还尝试用 if 语句检查它是否实际上是“3”,但我也得到了错误的返回。有人可以解释一下为什么它不起作用吗?
File imageFile = new File("C:\\Users\\Nils\\IdeaProjects\\untitled8\\Images\\Cutted\\"+i+m+".png");
ITesseract instance = new Tesseract(); // JNA Interface Mapping
// ITesseract instance = new Tesseract1(); // JNA Direct Mapping
instance.setDatapath("C:/Users/Nils/Desktop/blum/Tess4J/tessdata"); // path to tessdata directory
try {
String result = instance.doOCR(imageFile);
try {
resultI=Integer.parseInt(result);
numbers[0] = resultI;
}catch (NumberFormatException e){
numbers[0]=0;
}
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
最佳答案
好吧,我明白了。
if(result.length()>1)
result=result.substring(0,1);
删除所有导致错误的内容,但保留我想要分隔的数字。
关于java - Tess4J:结果字符串无法解析为int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62181402/