简单的验证码识别(通过颜色)

这是一个Java程序,使用Tesseract OCR库来识别图像中的验证码。首先,程序通过MyImgFilter类对图像进行预处理,包括转灰度、增强亮度,然后调用OrcTest类的recognizeText方法使用Tesseract进行文字识别。
摘要由CSDN通过智能技术生成


package com..luck;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import javax.imageio.ImageIO;

public class OrcTest_two {


/**
* @param args
* @throws Exception 
*/
public static void main(String[] args) throws Exception {
OrcTest orc = new OrcTest();
String imageFile = "D:\\testimg/tes.png";
//先通过MyImgFilter类对图片进行实现处理 去除干扰
FileInputStream fin = new FileInputStream(imageFile);
BufferedImage bi = ImageIO.read(fin);
MyImgFilter flt = new MyImgFilter(bi);
flt.changeGrey();
flt.getGrey();
flt.getBrighten();
bi = flt.getProcessedImg();
String pname = imageFile.substring(0, imageFile.lastIndexOf("."));
File file = new File(pname + ".jpg");
ImageIO.write(bi, "jpg", file);

///
//File file = new File(imageFile);
System.out.println(orc.recognizeText(file)+"12346579");
}

}


Class_two

package com.eduask.luck;


import java.io.BufferedReader;  
  
import java.io.File;  
import java.io.FileInputStream;  
import java.io.InputStreamReader;  
import java.util.ArrayList;  
import java.util.List;  
  
import org.jdesktop.swingx.util.OS;  
  
public class OrcTest  {  
    private final String LANG_OPTION = "-l";  
    private final String EOL = System.getProperty("line.separator");  
    /** 
     * 文件位置我防止在,项目同一路径 
     */  
    private String tessPath = new File("tesseract").getAbsolutePath();  
  
    /** 
     * @param imageFile 
     *            传入的图像文件 
     * @param imageFormat 
     *            传入的图像格式 
     * @return 识别后的字符串 
     */  
    public String recognizeText(File imageFile) throws Exception{  
        /** 
         * 设置输出文件的保存的文件目录 
         */  
        File outputFile = new File(imageFile.getParentFile(), "output");  
  
        StringBuffer strB = new StringBuffer();  
        List<String> cmd = new ArrayList<String>();  
        if (OS.isWindowsXP())  
        {  
            cmd.add(tessPath + "\\tesseract");  
        } else if (OS.isLinux())  
        {  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值