如何在使用 tesseract 阅读之前清理图像的文本?
How to clean an image's text before reading with tesseract?
我正在使用 tesseract 从图像中读取文本。由于我的 BinaryImage 输入不是纯白色背景上的简单文本,因此我只得到 50% 作为正确输出。
有什么方法可以预处理图像以便我可以从 tesseract 获得正确的输出吗?我已经尝试使用 Otsu's method 对图像进行灰度缩放和二值化,但没有任何改进。
由于我正在使用 java 执行所有这些操作,如果有人可以共享任何 java 库的详细信息或从 tesseract 获得更好结果的步骤,那将会很有帮助。
我也没有获得正确的 ImageMagick 文档以在我的 Java 代码中使用它。对此的任何帮助表示赞赏。
sample image ( any wireless bill of AT & T)
我认为您的账单扫描分辨率可能太小了。我相信如果您有更高分辨率的图像(更大的尺寸),您会得到更好的结果。您也可以尝试以无损压缩格式保存扫描件。您可以尝试局部区域阈值。但我认为这对这么小的文本没有帮助。不过,在 ImageMagick 中,您可以使用 -lat 命令来做到这一点。
convert image.jpg -negate -lat 25x25+10% -negate result.png
根据需要调整值。我还有一个 bash unix shell 脚本,textcleaner,它在其他图像上可能会更好。您可以在 http://www.fmwconcepts.com/imagemagick/textcleaner/index.php
查看示例
我尝试通过对图像进行灰度缩放和二值化来优化我的输出,但没有帮助。然后我尝试 boofcv 锐化我的图像,我得到了 90% 的优化输出。
在锐化图像之前,如果分辨率不够大,我们可以使用以下代码重新缩放图像:
public static BufferedImage scale(BufferedImage img, int imageType, int dWidth, int dHeight, double fWidth, double fHeight) {
BufferedImage img = null;
if(img != null) {
img = new BufferedImage(dWidth, dHeight, imageType);
Graphics2D g = img.createGraphics();
AffineTransform at = AffineTransform.getScaleInstance(fWidth, fHeight);
g.drawRenderedImage(img, at);
}
return img;
}
以防万一有人陷入同样的境地。
我正在使用 tesseract 从图像中读取文本。由于我的 BinaryImage 输入不是纯白色背景上的简单文本,因此我只得到 50% 作为正确输出。
有什么方法可以预处理图像以便我可以从 tesseract 获得正确的输出吗?我已经尝试使用 Otsu's method 对图像进行灰度缩放和二值化,但没有任何改进。
由于我正在使用 java 执行所有这些操作,如果有人可以共享任何 java 库的详细信息或从 tesseract 获得更好结果的步骤,那将会很有帮助。
我也没有获得正确的 ImageMagick 文档以在我的 Java 代码中使用它。对此的任何帮助表示赞赏。
sample image ( any wireless bill of AT & T)
我认为您的账单扫描分辨率可能太小了。我相信如果您有更高分辨率的图像(更大的尺寸),您会得到更好的结果。您也可以尝试以无损压缩格式保存扫描件。您可以尝试局部区域阈值。但我认为这对这么小的文本没有帮助。不过,在 ImageMagick 中,您可以使用 -lat 命令来做到这一点。
convert image.jpg -negate -lat 25x25+10% -negate result.png
根据需要调整值。我还有一个 bash unix shell 脚本,textcleaner,它在其他图像上可能会更好。您可以在 http://www.fmwconcepts.com/imagemagick/textcleaner/index.php
查看示例我尝试通过对图像进行灰度缩放和二值化来优化我的输出,但没有帮助。然后我尝试 boofcv 锐化我的图像,我得到了 90% 的优化输出。
在锐化图像之前,如果分辨率不够大,我们可以使用以下代码重新缩放图像:
public static BufferedImage scale(BufferedImage img, int imageType, int dWidth, int dHeight, double fWidth, double fHeight) {
BufferedImage img = null;
if(img != null) {
img = new BufferedImage(dWidth, dHeight, imageType);
Graphics2D g = img.createGraphics();
AffineTransform at = AffineTransform.getScaleInstance(fWidth, fHeight);
g.drawRenderedImage(img, at);
}
return img;
}
以防万一有人陷入同样的境地。