Tess4J:无法将结果字符串解析为int

我正在扫描单个字母和数字。所有数字都应解析为数字[]。但是它总是捕获异常。例如:结果为“ 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());
            }
iCMS 回答:Tess4J:无法将结果字符串解析为int

好吧,我知道了。

if(result.length()>1)
    result=result.substring(0,1);

删除所有引起错误的内容,但保留我要分隔的数字。

本文链接:https://www.f2er.com/2209777.html

大家都在问