tesseract图片文字识别 - 滤波 降噪 灰度 二值化 去除文本边框 去除验证码干扰线

import org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam;
import org.apache.xmlgraphics.image.codec.util.ImageEncoder;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class ImageUtil {
   

    public static void main(String[] args) throws IOException {
        File testDataDir = new File("pic");
        final String destDir = "picimages";
        for (File file : testDataDir.listFiles()) {
            cleanLinesInImage(file, destDir);
            cleanLinesInImage(file, destDir);
            cleanLinesInImage(file, destDir);
        }

    }

    /**
     * @param sfile   需要去噪的图像
     * @param destDir 去噪后的图像保存地址
     * @throws IOException
     */
    public static void cleanLinesInImage(File sfile, String destDir) throws IOException {
        File destF = new File(destDir);
        if (!destF.exists()) {
            destF.mkdirs();
        }

        BufferedImage bufferedImage = ImageIO.read(sfile);
        int h = bufferedImage.getHeight();
        int w = bufferedImage.getWidth();

        // 灰度化
        int[][] gray = new int[w][h];
        for (int x = 0; x < w; x++) {
            for (int y = 0; y < h; y++) {
                int argb = bufferedImage.getRGB(x, y);
                // 图像加亮(调整亮度识别率非常高)
                int r = (int) (((argb >> 16) & 0xFF) * 1.1 + 30);
                int g = (int) (((argb >> 8) & 0xFF) * 1.1 + 30);
                int b = (
  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论
首先,感谢您对OCR技术的关注。针对您的问题,我来为您提供一些解答。 Tesseract-OCR是一个免费的OCR引擎,可用于将图像中的文字转换为文本。而jTessBoxEditor是Tesseract-OCR提供的一个GUI界面,可以用于训练OCR识别模型,以提高其准确率。 以下是使用jTessBoxEditor提高OCR识别准确率的一些步骤: 1. 准备训练数据。首先需要准备一些训练图像和相应的文本文件,用于训练OCR模型。 2. 打开jTessBoxEditor。在菜单栏中选择“Tools”->“Merge Tiff”,将训练图像合并成一个多页Tiff文件。 3. 生成Box文件。在菜单栏中选择“Tools”->“Generate Box File”,对合并后的Tiff文件进行分页,并生成对应的Box文件。 4. 编辑Box文件。在菜单栏中选择“Tools”->“Box Editor”,打开Box文件并进行编辑。可以通过手动添加和删除Box框,来指定OCR识别的区域和内容。 5. 训练OCR模型。在菜单栏中选择“Tools”->“Train Tesseract”,进行OCR模型训练。训练完成后,会生成一个新的OCR语言包文件。 6. 测试OCR识别效果。在菜单栏中选择“Tools”->“Test Image”,用训练好的OCR语言包来对新的图像进行OCR识别,并评估识别准确率。 希望这些步骤能对您有所帮助,提高OCR识别率。同时,需要注意的是,OCR技术的准确率还受到许多因素的影响,如图像质量、文字大小、字体等。因此,在实际应用中,还需要针对具体的场景进行调整和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阳十三

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值