// Path: src/main/java/com/wind/common/Constants.java
// public interface Constants {
// 
//     /**********************************************分隔符常量************************************************/
// 
//     String POINT_STR = ".";
// 
//     String BLANK_STR = "";
// 
//     String SPACE_STR = " ";
// 
//     String NEWLINE_STR = "\n";
// 
//     String SYS_SEPARATOR = File.separator;
// 
//     String FILE_SEPARATOR = "/";
// 
//     String BRACKET_LEFT = "[";
// 
//     String BRACKET_RIGHT = "]";
// 
//     String UNDERLINE = "_";
// 
//     String MINUS_STR = "-";
// 
// 
// 
//     /**********************************************编码格式************************************************/
// 
//     String UTF8 = "UTF-8";
// 
// 
//     /**********************************************文件后缀************************************************/
// 
//     String EXCEL_XLS = ".xls";
// 
//     String EXCEL_XLSX = ".xlsx";
// 
//     String IMAGE_PNG = "png";
// 
//     String IMAGE_JPG = "jpg";
// 
//     String FILE_ZIP = ".zip";
//     String FILE_GZ = ".gz";
// 
// 
//     /**********************************************io流************************************************/
// 
//     int BUFFER_1024 = 1024;
// 
//     int BUFFER_512 = 512;
// 
//     String USER_DIR = "user.dir";
// 
//     /**********************************************tesseract for java语言字库************************************************/
// 
//     String ENG = "eng";
// 
//     String CHI_SIM = "chi_sim";
// 
// 
//     /**********************************************opencv************************************************/
//     String OPENCV_LIB_NAME_246 = "libs/x64/opencv_java246";
// 
//     String OPENCV_LIB_NAME_330 = "libs/x64/opencv_java330";
// }


import com.wind.common.Constants;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import net.sourceforge.tess4j.util.LoadLibs;
import java.io.File;
package com.wind.media;




/**
 * @Title: Tess4jUtil
 * @Package com.wind.image.ocr.tesseract
 * @Description: tesseract for java， ocr（Optical Character Recognition，光学字符识别）
 * @author huanghy
 * @date 2018/10/12 18:28
 * @version V1.0
 */
public class Tess4jUtil {

    /**
     * 从图片中提取文字,默认设置英文字库,使用classpath目录下的训练库
     * @param path
     * @return
     */
    public static String take(String path){
        // JNA Interface Mapping
        ITesseract instance = new Tesseract();
        // JNA Direct Mapping
        // ITesseract instance = new Tesseract1();
        File imageFile = new File(path);
        //In case you don't have your own tessdata, let it also be extracted for you
        //这样就能使用classpath目录下的训练库了
        File tessDataFolder = LoadLibs.extractTessResources("tessdata");
        //Set the tessdata path
        instance.setDatapath(tessDataFolder.getAbsolutePath());
        //英文库识别数字比较准确
// Path: src/main/java/com/wind/common/Constants.java
// public interface Constants {
// 
//     /**********************************************分隔符常量************************************************/
// 
//     String POINT_STR = ".";
// 
//     String BLANK_STR = "";
// 
//     String SPACE_STR = " ";
// 
//     String NEWLINE_STR = "\n";
// 
//     String SYS_SEPARATOR = File.separator;
// 
//     String FILE_SEPARATOR = "/";
// 
//     String BRACKET_LEFT = "[";
// 
//     String BRACKET_RIGHT = "]";
// 
//     String UNDERLINE = "_";
// 
//     String MINUS_STR = "-";
// 
// 
// 
//     /**********************************************编码格式************************************************/
// 
//     String UTF8 = "UTF-8";
// 
// 
//     /**********************************************文件后缀************************************************/
// 
//     String EXCEL_XLS = ".xls";
// 
//     String EXCEL_XLSX = ".xlsx";
// 
//     String IMAGE_PNG = "png";
// 
//     String IMAGE_JPG = "jpg";
// 
//     String FILE_ZIP = ".zip";
//     String FILE_GZ = ".gz";
// 
// 
//     /**********************************************io流************************************************/
// 
//     int BUFFER_1024 = 1024;
// 
//     int BUFFER_512 = 512;
// 
//     String USER_DIR = "user.dir";
// 
//     /**********************************************tesseract for java语言字库************************************************/
// 
//     String ENG = "eng";
// 
//     String CHI_SIM = "chi_sim";
// 
// 
//     /**********************************************opencv************************************************/
//     String OPENCV_LIB_NAME_246 = "libs/x64/opencv_java246";
// 
//     String OPENCV_LIB_NAME_330 = "libs/x64/opencv_java330";
// }


// Path: src/main/java/com/wind/media/Tess4jUtil.java
import com.wind.common.Constants;
import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
import net.sourceforge.tess4j.util.LoadLibs;
import java.io.File;

package com.wind.media;




/**
 * @Title: Tess4jUtil
 * @Package com.wind.image.ocr.tesseract
 * @Description: tesseract for java， ocr（Optical Character Recognition，光学字符识别）
 * @author huanghy
 * @date 2018/10/12 18:28
 * @version V1.0
 */
public class Tess4jUtil {

    /**
     * 从图片中提取文字,默认设置英文字库,使用classpath目录下的训练库
     * @param path
     * @return
     */
    public static String take(String path){
        // JNA Interface Mapping
        ITesseract instance = new Tesseract();
        // JNA Direct Mapping
        // ITesseract instance = new Tesseract1();
        File imageFile = new File(path);
        //In case you don't have your own tessdata, let it also be extracted for you
        //这样就能使用classpath目录下的训练库了
        File tessDataFolder = LoadLibs.extractTessResources("tessdata");
        //Set the tessdata path
        instance.setDatapath(tessDataFolder.getAbsolutePath());
        //英文库识别数字比较准确
        instance.setLanguage(Constants.ENG);