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())
{