【发布时间】:2017-02-28 12:31:39
【问题描述】:
我正在开发一个 Spring-MVC 应用程序,我们目前正在其中集成 OCR 功能。 OCR 习惯于在错误检测和背景中有图像时使用通配符。处理图像后,我们有相当好的数据可用,但仍然存在一些错误。我们想按如下方式处理输出
- 从输出字符串中删除所有单个字符。
- 删除除 A-Z、a-z、德语字符(即 äöü、ÄÖÜ、ß)以外的所有字符。
- 空格和数字应保持不变。
代码:
File imageFile = new File(fileLocation);
BufferedImage img = ImageIO.read(imageFile);
BufferedImage blackNWhite = new BufferedImage(img.getWidth(),img.getHeight(),BufferedImage.TYPE_BYTE_BINARY);
Graphics2D graphics = blackNWhite.createGraphics();
graphics.drawImage(img, 0, 0, null);
String blackAndWhiteImage = zipLocation + String.valueOf(new BigInteger(130, random).toString(32))+".png";
File outputfile = new File(blackAndWhiteImage);
ImageIO.write(blackNWhite, "png", outputfile);
ITesseract instance = new Tesseract();
// Point to one folder above tessdata directory, must contain training data
instance.setDatapath("/usr/share/tesseract-ocr/");
// ISO 693-3 standard
instance.setLanguage("deu");
String result = instance.doOCR(outputfile);
//System.out.println(result);
result = result.replaceAll("\\P{ASCII}","");
System.out.println("Result is "+result);
return result;
谢谢。
更新
正则表达式留下的通配符:
|
| '(°Ul")
_} °
=# '
( )
...................................__+_......_._._.__._._._+._._.
【问题讨论】:
-
正则表达式为
[öÖäÄüÜßa-zA-Z]